Jquery implements the method of disabling the browser's back: first open the corresponding js file; then disable the browser's back and next buttons through the "jQuery(document).ready(function () {...}" method That’s it.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, thinkpad t480 computer.
Recommendation: " jquery video tutorial》
jquery disables the browser back button
Use Jquery to disable the browser's back and next buttons:
Sometimes for To prevent users from messing up the access sequence and having to disable the browser's forward and back buttons
jQuery(document).ready(function () { if (window.history && window.history.pushState) { $(window).on('popstate', function () { // 当点击浏览器的 后退和前进按钮 时才会被触发, window.history.pushState('forward', null, ''); window.history.forward(1); }); } //在IE中必须得有这两行 window.history.pushState('forward', null, ''); window.history.forward(1); });
This code mainly uses the window.history object of js;
For example:
If the URL of the current page is: http://localhost:28713/SBNext/index.aspx
Execution: window.history.pushState('forward', null, 'badu.aspx');
Result: Add a record http://localhost:28713/SBNext/index.aspx in the browser history. The url of the current page becomes http://localhost:28713/SBNext/badu.aspx, but The page will not be refreshed, nor will the URL be checked to see if it is correct. At this time, if you click the browser's back button, it will return to the http://localhost:28713/SBNext/index.aspx page, which is still the current page. So this is the above disabled The principle of the back button.
The above is the detailed content of How to disable browser back in jquery. For more information, please follow other related articles on the PHP Chinese website!