如何禁用浏览器的后退按钮,使用 JavaScript?
要禁用浏览器后退按钮,请尝试运行以下代码,这是当前 HTML 页面的代码,
示例
<html> <head> <title>Disable Browser Back Button</title> <script src = "http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> </head> <body> <a href = "newpage.html">Next Page</a> </body> <script> $(document).ready(function() { function disablePrev() { window.history.forward() } window.onload = disablePrev(); window.onpageshow = function(evt) { if (evt.persisted) disableBack() } }); </script> </html>
以下是 newpage.html 的代码,
<html> <body> Go to back page using web browser back button. </body> </html>a
广告