9

I am using the following code to show a page with a Twitter box already filled in with a message:

<a href="http://www.twitter.com/share.php?url=http://myurl.com&text=myMessage" target="_blank">Click me</a>

However, on the page, I am getting this inside the Twitter box:

myMessage/

Note the trailing slash. Any ideas how to fix this?

steacha
  • 171
  • 5
  • 13

4 Answers4

9

We have found a workaround for this, where you add the source=webclient parameter, crucially, to the END of the twitter address. When you do this, Twitter no longer adds the trailing slash. However, given how Twitter like to change their formats and codes around, there's no guarantee this will work forever :-)

For example...

<a href="https://twitter.com/intent/tweet?text=http://www.rsc.org%2FEducation%2FEiC%2Fissues%2F2013January%2F50th%2Delement%2Dtin%2Easp&amp;source=webclient" target="_blank">Twitter this</a>
  • how did you find out? that's so weird! – Karol Feb 19 '14 at 03:03
  • This is stupid!!! I'm sharing URL which looks like `http://website.com/page?info=data`. Of course I can't add the tralining slash after `data`, this would broke my URL! :( – Mike Keskinov Jan 29 '16 at 21:09
5

No, the solution is more simple. URL-encode your url :

https://twitter.com/intent/tweet?text=myMessage&url=http%3A%2F%2Fmyurl.com
  • 1
    Nope. My URL encoded, still the same problem. Need to add traling slash, but it's not always possible (if I have get parameters, I can't add the slash after them) – Mike Keskinov Jan 29 '16 at 21:10
3

Add a trailing slash to your URL and that should go away. It worked for me.

Change the URL from this:

http://www.twitter.com/share?url=http://myurl.com&text=myMessage

To this:

http://www.twitter.com/share?url=http://myurl.com/&text=myMessage
tnylea
  • 189
  • 1
  • 6
2

As Twitter documentation claims (twitter original reference):

A fully-qualified URL with a HTTP or HTTPS scheme, URL-encoded.

Fully-qualified URL requires to have trailing slash. From the same documentation:

Example Value: http:%3A%2F%2Fexample.com%2F

Note, that the example has %2F at the end, which is HTML encoded / character. Twitter tries to create correct URL by appending / automatically.

Set your url GET parameter to http://myurl.com/ to get rid of the trailing slash

agoldis
  • 1,067
  • 16
  • 28
  • This works well. For those finding this question 2 years later like me, try this out. I am dynamically sharing by using ```window.location.origin``` which does not add a trailing slash to the url and caused Twitter to add one to my tweet message. However, doing ```window.location.origin + '/'``` worked. – Martavis P. Feb 25 '16 at 06:26