JavaScript implementation prompt function before leaving the page [attached jQuery implementation method]

The instance of this article describes the prompt function before JavaScript implementation leaves. Share to everyone for reference, the specific:

The prompt before leaving the page cannot be done with ONUNLOAD, because it is just compatible with IE, you have to be compatible with Firefox.

And this event is still triggered after it is closed.

Instead, you can use OnBeforeunLoad to achieve it.

Onbeforeunload can trigger in the user to close or refresh the window, or click any hyperlinks in this page.

Window.onbeforeunload = function (e) {var e = window.event || E; E. RETURNVALUE = (“Is it sure that left the current page?”);}
   Very short, using Window.event and E or, compatible browser.   The return value is prompt information. 
The effect of IE8 is as follows, and the first line must exist in the last line. Users click “Cancel” without anything, and click “OK” to continue the previous action.

The effect in Google Chrome is as follows, only the last line is what we can control, others have something that the system itself is, and cannot be rewritten.

The effect of wild fox is as follows, and the prompt information can’t be read, I can’t help, who is this browser is a wild fox?

JavaScript实现离开页面前提示功能【附jQuery实现方法】

This piece of things, use jQuery to write:

$ (Window) .bind (‘BeforeunlOAD ‘, FUNCTION () {RETURN’ Tip Information ‘;};

JavaScript实现离开页面前提示功能【附jQuery实现方法】 jQuery1.9 comes with full browser compatibility …

More Readers who are interested in JavaScript can view this topic: “JavaScript page element operation skill summary”, “JavaScript regular expression skills”, “JavaScript Find Algorithm Skills Summary”, “JavaScript Data Structure and Algorithm Skills Summary”, “JavaScript Hybrid Algorithm and Skills Summary”, “JavaScript Error and Debugging Skill Summary” and “Summary of JavaScript Mathematical Computing Usage”

I hope this article will help you JavaScript programming. JavaScript实现离开页面前提示功能【附jQuery实现方法】

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment