Onpagehide, OnUnload and Onpageshow, onload events puzzled

Source: Internet
Author: User

Today in the latest version of the Chrome browser test under what circumstances will trigger Onpagehide, onunload events (click on a link, refresh the page, submit the form, close the browser, etc.). The test code is pasted as follows:

<! DOCTYPE html>
<title> Testing </title>
<meta charset= ' Utf-8 ' >
<script type= "Text/javascript" >
function Onpageshowfunc () {
Alert ("Onpageshow ()");
}
function Onloadfunc () {
Alert ("Onloadfunc ()");
}
function Onunloadfunc () {
Console.log ("2222222222");
Alert ("Onunloadfunc ()");
}
function Onpagehidefunc () {
Console.log ("111111111");
Alert ("Onpagehide ()");
}
</script>
<body onunload= "Onunloadfunc ()" Onpagehide= "Onpagehidefunc ()" onpageshow= "Onpageshowfunc ()" Onload= "Onloadfunc ( ) ">
<a href= "http://www.baidu.com" >test link baidu</a>
</body>

Results found unexpectedly:

1, Onpagehide onunload event is triggered after destroying the Page object, onbeforeunload is triggered before destroying the Page object, when the alert () method has been locked destroyed, and thus has not been able to pop up the prompt box, and then the breakpoint prompt an error output " Blocked alert (' Onpagehide () ') during pagehide. "Blocked alert (' Onunloadfunc () ') during unload."

2, onpagehide than onunload first trigger.

3, onload than onpageshow first trigger.

Above only their own conclusions, welcome correction.

Onpagehide, OnUnload and Onpageshow, onload events puzzled

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.