encodeURIComponent - twitter replaces & with &

时间:2015-10-29 15:56:19

标签: jquery twitter encodeuricomponent

I got a small code, that generates a Twitter-Button from a html element.

$('.article').append(function() {
 var tweet = $(this).find('.tweet').html();
 var twitterurl = 'https://twitter.com/home/?status=' + encodeURIComponent(tweet);
return "<a class='btn btn-primary' href='" + twitterurl + "'>Share on Twitter</a>";
});

It's working generally, but: somehow the original text gets encoded twice. I noticed that when a & character was decoded by twitter to &amp. I traced it back and found that my script generates a url including %26amp . That of course is decoded by twitter to &amp. Thanks for any help to solve this!

0 个答案:

没有答案