简体   繁体   中英

How to disable the back button in the iPad's browser

Below is my code to detect and stop the browser's back button in iPad browsers.

$(window).bind("pagehide", function(e) { 
})

How can I stop the page going back on browsers' back button click in iPad browsers?

You can use the onbeforeunload event that triggers when a user is leaving your page, whether it's by hitting the back button, entering a new URL or closing the browser.

Here is an example:

window.onbeforeunload = function(){
    return 'You are leaving!?';
}

And here is the result on Chrome:

在此处输入图片说明

This event seems to be inconsistent across browsers as some will not support it, some will execute whatever function you pass it, and some will reject the function if it doesn't return a string to put in the confirmation box.

As commenter Alex Wayne stated, think twice about this. It can really create a negative impact on your site or webapp to alter the native behaviour of the back button.

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