如何在javascript中将encodeURIComponent加倍? [英] How to double encodeURIComponent in javascript?

查看:88
本文介绍了如何在javascript中将encodeURIComponent加倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我使用mailto链接打开Outlook2007。我还将URL插入到正文中。问题是我需要整个URL为超链接。如果有空格,则超链接会中断,或者即使有特殊字符(例如,如果它以一个紧密的括号结尾),该字符也不会包含在超链接中,因此链接会中断。

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.

我尝试过的是在链接上使用 encodeURIComponent ,该链接会对其进行编码,但问题是在Outlook中,它将自动将其解码回正常然后断开链接。我需要的是对它进行双重编码的方法。

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.

基本上不是这样做

-> %20 (<-- encodeURIComponent

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

我需要

-> %2520

因此,在前景中,%25 被解码为,当与 20 结合使用时,我得到%20 保持链接编码一次且不中断。这对我有用,但我只是不知道该怎么做。

So that in outlook, the %25 gets decoded to %, which when combines 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?

谢谢

推荐答案

编码

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

解码

 var decoded=decodeURIComponent(unescape(encoded));

这篇关于如何在javascript中将encodeURIComponent加倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆