[英]JavaScript replace behaves differently in Chrome to IE
The following JavaScript works perfectly in Chrome to replace a string: 以下JavaScript在Chrome中可以完美地替换字符串:
myUrl = someUrl.replace('%2C%7B%22itn%22%3A%5B%22%20guidelines%20%22%5D%7D', '');
but in Internet Explorer it fails to replace the string. 但是在Internet Explorer中,它无法替换字符串。
It seems that it is related to how IE treats %22
as if I debug this code and replace %22
with "
it works in debug. If I try doing this in the script itself it then errors in both Chrome and IE. 看来这与IE如何对待
%22
就像我调试此代码并将%22
替换为"
它在调试中起作用。 "
。如果我尝试在脚本本身中执行此操作,则Chrome和IE均会出错。
How can I make this script work cross browser? 如何使该脚本跨浏览器工作?
It's a known bug in Internet Explorer that it doesn't encode "
in the query string part of a URL. Try replacing URLs both when %22
and "
are used. 这是Internet Explorer中的一个已知错误 ,它没有在URL的查询字符串部分中对
"
进行编码。尝试同时使用%22
和"
时替换URL。
For example, it is possible to do this using a regular expression : 例如,可以使用正则表达式执行此操作:
myUrl = someUrl.replace(/%2C%7B%22itn(?:%22|")%3A%5B(?:%22|")%20guidelines%20(?:%22|")%5D%7D/, '');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.