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