javascript encodeURIComponent returning additional characters
For some reason, I am getting additional code in my encoded URI's with javascript encodeURIcomponent function, namely %25 character:
My function i开发者_运维技巧s:
function twit_click() {
var u="https://www.website.com/<?php echo $_SESSION['id'];?>";
var t="sometext";
window.open('http://www.twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t),'twitsharer','toolbar=0,status=0,width=626,height=436');
return false;
}
when I click the text and call twit_click() function, I get the following URL:
http://twitter.com/intent/tweet?text=sometext&url=https%253A%252F%252Fwww.website.com%252Fuserid
as opposed to what it should be:
http://twitter.com/intent/tweet?text=sometext&url=https%3A%2F%2Fwww.website.com%2Fuserid
am I missing something? It is adding in additional "25" characters which would imply I have % in my URI which I clearly do not.
Remove the "www" from "www.twitter" and it works.
http://jsfiddle.net/tzkpz/
Twitter must be re-encoding the URL when it redirects from www.twitter.com to twitter.com, hence the double encoding.
精彩评论