javascript(在 Firefox 插件中)停止页面加载
首先:一切正常,但我想稍微调整一下。
基本上,在我的 FireFox 插件中,我在函数 A: 中包含此代码
timervar = setTimeout(function() { quick.redirectToAnotherUrl(); },1500);
,在 redirecttoanotherurl 函数中,我有此代码:
window.content.location.href = FilterUrl;
问题是页面在重定向生效之前加载。 无论如何,是否可以完全停止页面加载,然后正常重定向?
First off: Everything works, but I would like to fine tune this a little.
Basically, in my FireFox addon I have this code in function A:
timervar = setTimeout(function() { quick.redirectToAnotherUrl(); },1500);
and in the redirecttoanotherurl function I have this:
window.content.location.href = FilterUrl;
The problem is the page loads before the redirect takes effect.
Is there anyway to stop the page loading totally and then redirect as normal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定浏览器兼容性,但也许在
setTimeout
之前尝试window.stop();
?对于IE,您可能还需要
document.execCommand('Stop');
,因为据我所知,它不支持window.stop()
。I'm not sure of the browser compatibility, but maybe try
window.stop();
before yoursetTimeout
?For IE, you may need
document.execCommand('Stop');
in addition, because as far as I know, it does not supportwindow.stop()
.您在
setTimeout
的参数中指定了 1.5 秒的延迟。事实上,如果您想要立即重定向,我根本不明白您为什么要使用
setTimeout
。只需立即设置
window.content.location.href
即可。You have a 1.5s delay specified in your argument to
setTimeout
.In fact, if you want an immediate redirect, I don't understand why you're using
setTimeout
at all.Just set
window.content.location.href
immediately.