简体   繁体   English

如何在单击后退按钮时阻止网页加载?

[英]how to stop a webpage from loading on clicking back button?

I m trying to disable a page from loading on click of back button after it is redirected to some certain pages. 我试图在将页面重定向到某些特定页面后,单击后退按钮以使其无法加载。 I have used onunload event but it stops loading of the page after visiting any page. 我已经使用过onunload事件,但是访问任何页面后它都会停止加载页面。

<script type = "text/javascript" >

function preventBack() {
    window.history.forward();
}
setTimeout("preventBack()", 0); 
window.onunload = function() {
    null
};

</script>

Also suggest if i could use window.stop(); 还建议我是否可以使用window.stop(); Any help will be appreciated. 任何帮助将不胜感激。

If the page it comes from isn't your page, you can't do anything about that. 如果它来自的页面不是您的页面,那么您将无能为力。 All timeouts/JavaScript will be cleared when your page is unloaded, and null inside a handler does absolutely nothing. 卸载页面后,所有超时/ JavaScript都将被清除,并且处理程序中的null绝对不起作用。

This is a user-friendliness thing that browsers do, because not being able to go back would be horrible. 这是浏览器的用户友好性,因为无法返回将是可怕的。 Please rethink your approach. 请重新考虑您的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM