Cases
| The code is as follows |
Copy Code |
Window.onbeforeunload = function () {return you have unsaved content! ';} |
If you are referencing jquery, you can also use jquery for easy implementation, as follows JS code:
| The code is as follows |
Copy Code |
$ (window). bind (' Beforeunload ', function () {return you have unsaved content! ';}); |
Let's look at a more complete example.
| The code is as follows |
Copy Code |
Window.onbeforeunload = function () { var ie =!-[1,]; if (IE) { var n = window.event.screenx-window.screenleft; var b = n > document.documentelement.scrollwidth-20;
if (!) ( b && Window.event.clientY < 0 | | Window.event.altKey)) {
}else{ Return "Do not close a new site, okay?" Www.111cn.net "; } }else{ Return "Do not close a new site, okay?" Www.111cn.net "; } } |
Small Tips
Window.onbeforeunload only for us to leave the page or close a hint, but I test like a multi-window browser Click x Close is not prompted, and directly close the browser is not prompted, only refresh the page to be prompted OH.