url - How to double encodeURIComponent in javascript? - Stack Overflow

In my web app, I use a mailto link to open the outlook 2007. I also insert a url into the body. The pro

In my web app, I use a mailto link to open the outlook 2007. I also insert a url into the body. The problem is I need the whole url to be a hyperlink. If there is any spaces, then the hyperlink breaks, or even if there is any special characters like if it ends with a close parenthesizes the character wont be included in the hyperlink, so the link breaks.

What I tried was using encodeURIComponent on the link, which url encodes it, but the issue is that in outlook, it will automatically decode it back to normal which then breaks the link. What I need is a way to double encode it.

Basically instead of doing

" " -> "%20" (<-- encodeURIComponent)

I need

" " -> "%2520"

So that in outlook, the %25 gets decoded to %, which when bines with the 20 so I get %20 keeping the link encoded once and not broken. This is what would work for me, but I just don't know how to do this function.

Does anyone know how I can do this double encode?

Thanks

In my web app, I use a mailto link to open the outlook 2007. I also insert a url into the body. The problem is I need the whole url to be a hyperlink. If there is any spaces, then the hyperlink breaks, or even if there is any special characters like if it ends with a close parenthesizes the character wont be included in the hyperlink, so the link breaks.

What I tried was using encodeURIComponent on the link, which url encodes it, but the issue is that in outlook, it will automatically decode it back to normal which then breaks the link. What I need is a way to double encode it.

Basically instead of doing

" " -> "%20" (<-- encodeURIComponent)

I need

" " -> "%2520"

So that in outlook, the %25 gets decoded to %, which when bines with the 20 so I get %20 keeping the link encoded once and not broken. This is what would work for me, but I just don't know how to do this function.

Does anyone know how I can do this double encode?

Thanks

Share Improve this question asked Aug 23, 2013 at 15:56 omegaomega 44k90 gold badges286 silver badges523 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Encode

var encoded=escape(encodeURIComponent(' '));

Decode

 var decoded=decodeURIComponent(unescape(encoded));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744268649a4565988.html

相关推荐

  • url - How to double encodeURIComponent in javascript? - Stack Overflow

    In my web app, I use a mailto link to open the outlook 2007. I also insert a url into the body. The pro

    7天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信