Google chrome extension 在全局上下文中停止window.location执行
当页面加载时,我想停止执行window.location,如下所示:Google chrome extension 在全局上下文中停止window.location执行,google-chrome-extension,firefox-addon-webextensions,Google Chrome Extension,Firefox Addon Webextensions,当页面加载时,我想停止执行window.location,如下所示: <script type="text/javascript"> alert('Bid closed '); window.location = '/index.html'; </script> 警报(“投标结束”); window.location='/index.html'; 我可以通过在manifest.json中的document\u start期间替换alert函数来绕过alert消息。但
<script type="text/javascript">
alert('Bid closed ');
window.location = '/index.html';
</script>
警报(“投标结束”);
window.location='/index.html';
我可以通过在manifest.json中的
document\u start
期间替换alert
函数来绕过alert
消息。但无法停止window.location的执行。窗口
对象不可写,因此无法更改文档
和窗口
对象
查看此项了解更多信息在我看来,答案就像一个数学难题 在注入的脚本中,我刚刚放置了以下代码,它似乎可以工作:
window.alert =
function (msg)
{
throw Error('hello');
}
此异常导致浏览器跳过下一个语句
窗口。location=
根据条件发出警报?当然不是。要回答此问题,请在问题中具体说明您希望停止执行该确切代码。目前的问题是如何停止执行设置window.location
。在不知道您想要停止该确切代码的情况下,这似乎并不能真正回答问题。@Makyen这是我所问问题的解决方案。我已经用我在问题中提出的代码进行了测试。