Js window close prompt information (compatible with IE and firefox), jsfirefox
In many cases, when browsing a webpage, we need to consider closing the window when users are not careful, especially when important data is not saved, it is necessary for our program to remind users. In this case, we can use javascript window. onbeforeunload () to prevent users from closing the window. See the following example:
<Script type = "text/javascript"> window. onbeforeunload = function (event) {return 'hello' ;}</script>
In this way, when you press the close button, the following window will pop up (compatible with IE and firefox ):
"Hello" is the return value. When you press Cancel, the page will not be closed. Only after you press OK. The return value is indispensable, even if it is null, otherwise the page will be closed without any prompts. In fact, as long as the window is called. close () will execute the onbeforeunload () function, so we can know that the window will be executed by pressing the close button. close () function, while window. in close (), window is also called. onbeforeunload () function.
With this tips, you no longer have to worry about the losses caused by accidental window close. I hope you will like this article.