admin管理员组

文章数量:1194115

I am trying to add custom tweet button to my website and all is well but it is not shortening the URL. I am using URL query string instead of javascript. Is that the case?

<a class="btn btn-tweet" target="_blank" href="='.$title.'&url='.$url.'&via='.$user.'&wrap_links=true">Twitter</a>

I have read some API document and saying above 19 characters twitter shorten url itself. Just wonder why it is not converting with this.

I am also having trouble to open in popup instead of new window. Does this all possible without adding any separate javascript code but directly inline in anchor tag?

I am trying to add custom tweet button to my website and all is well but it is not shortening the URL. I am using URL query string instead of javascript. Is that the case?

<a class="btn btn-tweet" target="_blank" href="https://twitter.com/share?text='.$title.'&url='.$url.'&via='.$user.'&wrap_links=true">Twitter</a>

I have read some API document and saying above 19 characters twitter shorten url itself. Just wonder why it is not converting with this.

I am also having trouble to open in popup instead of new window. Does this all possible without adding any separate javascript code but directly inline in anchor tag?

Share Improve this question asked Jan 2, 2014 at 18:03 Code LoverCode Lover 8,34821 gold badges90 silver badges164 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 22

I was hung up on this and realized I was trying to shorten "http://localhost:5000/blog/url" which t.co is unable to do.

Change to a real, non-localhost URL and it worked fine.

It won't be visibly shortened in the compose window, but the compose window does detect URLs and adjusts the character count accordingly. Try pasting a huge long URL - it'll only use up 22 characters in the count.

Do note that Twitter shortens all URLs, even when "shortening" actually makes them longer. For example, "http://bit.ly" will use up 22 characters (not 19), not 13.

本文标签: javascriptTwitter auto shorten URL not workingStack Overflow