在全局上下文中停止window.location执行

时间:2017-04-03 06:55:24

标签: google-chrome-extension firefox-webextensions

我希望在页面加载时停止执行window.location,如下所示:

<script type="text/javascript">
alert('Bid closed ');
window.location = '/index.html';
</script>

我可以通过在manifest.json中的alert期间替换alert函数来绕过document_start消息。但是无法阻止window.location执行。

2 个答案:

答案 0 :(得分:2)

window对象不可写,因此您无法更改documentwindow个对象 查看此link了解详情

答案 1 :(得分:0)

答案在我看来就像是一个数学难题。

在注入的脚本中,我刚刚放置了这段代码,它似乎有效:

window.alert =
                function (msg)
                    {
                       throw Error('hello');
                    }

此异常导致浏览器跳过下一个语句window.location=