Summary _javascript skills of similarities and differences between onbeforeunload and OnUnload events

Source: Internet
Author: User
1) Similarities and differences
Same point: Onunload,onbeforeunload are called at refresh or shutdown, can be specified in <script> scripts by window.onunload or in <body>.
Different points:
A) onbeforeunload is executed before onunload, and it can also block onunload execution.
b onbeforeunload is about to go to the server to read the new page when the call, at this time has not started reading; Nunload has read from the Server a new page that needs to be loaded, which is called when the current page is about to be replaced.
c) onbeforeunload can prevent pages from being updated and closed. But OnUnload can't.
The order in which the OnLoad, onbeforeunload, onunload events are executed:
When a page is opened: Only the onload is performed
When closing a page: First onbeforeunload, after onunload
Refresh page: First onbeforeunload, after OnUnload, then onload

2) onbeforeunload, onunload events
Trigger on:
A) Close the browser window
b When you go to another page via the Address bar or favorites
c) Click Back, Forward, refresh, homepage one of the time
d click on a URL to another page to connect the time
e) When invoking any of the following events: Click,document write,document open,document close,window Close, window navigate, window Navigateandfind,location replace,location Reload,form Submit.
f when opening a page with window open and passing the name of the window on this page to the page you want to open.
g) When the value of the LOCATION.HREF is again assigned.
h) Submit a form with the specified action through the input type= "submit" button.
Can be used in the following elements:
Body, FRAMESET, window
Browser support:
Ie4+/win, Mozilla 1.7a+, Netscape 7.2+, firefox0.9+

3) Resolve to refresh the page without calling onbeforeunload

4 onbeforeunload Prevent pages from being updated and closed
Onbeforeunload= "Return" is now leaving this page '; ' >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.