How to implement Wechat browser to prevent page dragging by jquery
This article mainly explains "jquery how to achieve Wechat browser to prevent page drag", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "jquery how to achieve Wechat browser to stop page drag" bar!
Jquery implements the method of disabling browser fallback by first opening the corresponding js file, and then disabling the browser's back and next buttons through the "jQuery (document) .ready (function () {...}" method.
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, thinkpad T480 computer.
Jquery disable browser back button
Use Jquery to disable the browser's back and next buttons:
Sometimes, in order to prevent users from getting out of order, they have to disable the forward and backward buttons of the browser jQuery (document) .ready (function () {
If (window.history & & window.history.pushState) {
$_ (window) .on ('popstate', function () {
/ / it will be triggered when the browser's back and forward buttons are clicked.
Window.history.pushState ('forward', null,'')
Window.history.forward (1)
})
}
/ / these two lines are required in 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:
Execute: window.history.pushState ('forward', null,' badu.aspx')
The result: adding a url to the browser history that records the current page becomes, but the page is not refreshed and the url is not checked for correctness. At this point, if you click the browser's back button, it will go back to the page, or the current page. So that's how the back button is disabled above.
Thank you for your reading, the above is the content of "jquery how to achieve Wechat browser to prevent page dragging". After the study of this article, I believe you have a deeper understanding of how jquery implements Wechat browser to prevent page dragging, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!