Home >Web Front-end >JS Tutorial >Prompt onbeforeunload event when closing the browser_javascript tips
onbeforeunload event This is how it is used:
The excerpt is as follows: onbeforeunload event:
Note: Firefox and IE among the three major browsers support the onbeforeunload event, but Opera does not yet support it.
Usage:
object.onbeforeunload = handler
Description: When the event is triggered, a dialog box with confirmation and cancellation will pop up. If you confirm, you will leave the page. , cancel to stay on this page. The handler can set a return value as the displayed text of the dialog box.
Close the browser window
When going to other pages through the address bar or favorites
When clicking Return, Forward, Refresh, or Home Page
When clicking a url link to other pages
When calling any of the following events: click, document write, document open, document close, window close, window navigate, window NavigateAndFind, location replace, location reload, form submit.
When using window open to open a page, And pass the name of the window of this page to the page to be opened.
When reassigning the value of location.href.
When submitting a form with a specified action through the input type="submit" button.
can be used in the following elements: BODY, FRAMESET, window