简体   繁体   中英

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.

<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(); 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.

This is a user-friendliness thing that browsers do, because not being able to go back would be horrible. Please rethink your approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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