替换为JavaScript转义?
我知道转义函数已被弃用,您应该使用encodeURI或encodeURIComponent。 但是,encodeUri和encodeUriComponent与escape不同。
我想用瑞典语在JavaScript中创建一个mailto链接。 下面是escape,encodeURIComponent和encodeURI之间的比较:
console.log("mailto:?subject="+escape(subject)+"&body=" + escape(body));
console.log("mailto:?subject="+encodeURIComponent(subject)+"&body=" + encodeURIComponent(body));
console.log("mailto:?subject="+encodeURI(subject)+"&body=" + encodeURI(body));
Output:
mailto:?subject=My%20subject%20with%20%E5%E4%F6&body=My%20body%20with%20more%20characters%20and%20swedish%20%E5%E4%F6
mailto:?subject=My%20subject%20with%20%C3%A5%C3%A4%C3%B6&body=My%20body%20with%20more%20characters%20and%20swedish%20%C3%A5%C3%A4%C3%B6
mailto:?subject=My%20subject%20with%20%C3%A5%C3%A4%C3%B6&body=My%20body%20with%20more%20characters%20and%20swedish%20%C3%A5%C3%A4%C3%B6
只有使用“转义”创建的mailto链接才能在Outlook中使用IE或Chrome打开格式正确的邮件。 当使用encodeURI或encodeURIComponent时,主题说:
My subject with åäö
身体也看起来很乱。
除了转义之外,还有其他一些函数可用于获取正在运行的mailto链接吗?
escape()函数在JavaScript 1.5版中已弃用。 改为使用encodeURI()或encodeURIComponent()。
例
string: "May/June 2016, Volume 72, Issue 3"
escape: "May/June%202016%2C%20Volume%2072%2C%20Issue%203"
encodeURI: "May/June%202016,%20Volume%2072,%20Issue%203"
encodeURIComponent:"May%2FJune%202016%2C%20Volume%2072%2C%20Issue%203"
来源https://www.w3schools.com/jsref/jsref_escape.asp
链接地址: http://www.djcxy.com/p/26525.html