问题
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 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?
Thanks
回答1:
Encode
var encoded=escape(encodeURIComponent(' '));
Decode
var decoded=decodeURIComponent(unescape(encoded));
来源:https://stackoverflow.com/questions/18407078/how-to-double-encodeuricomponent-in-javascript