在 IE11 中将 © window.location 与 © 任意位置设置为 IE11?



在IE11中,使用window.location, window.location.hrefdocument.location都有相同的效果。如果您设置的URL查询字符串中任意位置包含&copy,则将查询字符串修改为©

有什么办法解决这个问题吗?

要查看这个问题的演示,将以下文本保存到一个名为test.html的文件中,并在IE11中打开它。(这个bug也可能影响其他版本;我不知道。

<!DOCTYPE html5>
<html>
<body>
    <div><a href="#" class="broken">Broken in IE11</a></div>
    <div><a href="#" class="works">Works in IE11</a></div>
    <p>Query string: <pre id="queryString"></pre></p>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script>
        var queryString = (function() {
            if (!window.location.search) {
                return({});   // return empty object
            }
            var parms = {};
            var temp;
            var items = window.location.search.slice(1).split("&");   // remove leading ? and split
            for (var i = 0; i < items.length; i++) {
                temp = items[i].split("=");
                if (temp[0]) {
                    if (temp.length < 2) {
                        temp.push("");
                    }
                    parms[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
                }
            }
            return(parms);
        })();
        $(function() {
            $('#queryString').text(JSON.stringify(queryString));
            $('.broken').on('click', function(e) {
                e.preventDefault();
                window.location = "test.html?q=test&copy=true";
            });
            $('.works').on('click', function(e) {
                e.preventDefault();
                window.location = "test.html?copy=true&q=test";
            });
        });
    </script>
</body>
</html>

这个问题似乎影响了所有的IE版本,并且没有修复或解决方法允许确切的URL工作;你必须更改URL。

在查询字符串中使用

url编码的名称和值即可。将上面的示例修改为使用%63opy而不是copy,将会加载正确的URL。

参见:url中的意外HTML实体

最新更新