开发者

javascript encodeURIComponent returning additional characters

开发者 https://www.devze.com 2023-04-10 11:49 出处:网络
For some reason, I am getting additional code in my encoded URI\'s with javascript encodeURIcomponent function, namely %25 character:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号