简体   繁体   English

如何在iPad浏览器中禁用后退按钮

[英]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. 以下是我的代码,用于检测和停止iPad浏览器中浏览器的后退按钮。

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

How can I stop the page going back on browsers' back button click in iPad browsers? 如何在iPad浏览器中单击浏览器的后退按钮时停止页面返回?

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. 您可以使用onbeforeunload事件,该事件在用户离开页面时触发,无论是通过单击“后退”按钮,输入新URL还是关闭浏览器。

Here is an example: 这是一个例子:

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

And here is the result on Chrome: 这是在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. 正如评论员亚历克斯·韦恩(Alex Wayne)所说,对此请三思。 It can really create a negative impact on your site or webapp to alter the native behaviour of the back button. 它确实会对您的网站或Web应用造成负面影响,从而改变“后退”按钮的本机行为。

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

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