javascript - Escaping & for display in mail client (mailto link) -


i have javascript function so:

var strbody = encodeuri(window.location.href); var strsubject = encodeuri(document.title); var mailto_link = "mailto:?subject=" + encodeuri(strsubject) + "&body=" + strbody; 

this code executed on hyperlink's onclick event, , opens mail client (mailto://). however, title of page has several & symbols, title picked until first &. url picked up.

what correct javassript escape & , display in mail client's subject line?

var encoded_body = encodeuricomponent(window.location.href); var encoded_subject = encodeuricomponent(document.title); var mailto_link = "mailto:?subject=" + encoded_subject + "&body=" + encoded_body; 

should (encodeuricomponent instead of encodeuri).

in original code incorrectly double encoding subject (once on line 2, , again on line 3).

i took liberty of renaming variables make clearer contain encoded subject , body, opposed original text.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -