Home > Web Front-end > JS Tutorial > Prompt onbeforeunload event when closing the browser_javascript tips

Prompt onbeforeunload event when closing the browser_javascript tips

WBOY
Release: 2016-05-16 17:07:12
Original
1382 people have browsed it

onbeforeunload event This is how it is used:

Copy code The code is as follows:





In this way, every time the browser window is closed or a new page is opened, the onbeforeunload event will be triggered.

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.

Triggered by:

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

Platform support: IE4 /Win, Mozilla 1.7a, Netscape 7.2, Firefox0.9

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template