file_beforeunload_and_bfcache.html (855B)
1 <html> 2 <head> 3 <script> 4 onpageshow = function(pageShowEvent) { 5 var bc = new BroadcastChannel("beforeunload_and_bfcache"); 6 bc.onmessage = function(event) { 7 if (event.data == "nextpage") { 8 bc.close(); 9 location.href += "?nextpage"; 10 } else if (event.data == "back") { 11 bc.close(); 12 history.back(); 13 } else if (event.data == "forward") { 14 onbeforeunload = function() { 15 bc.postMessage("beforeunload"); 16 bc.close(); 17 } 18 history.forward(); 19 } else if (event.data == "close") { 20 bc.postMessage("closed"); 21 bc.close(); 22 window.close(); 23 } 24 }; 25 bc.postMessage({type: pageShowEvent.type, persisted: pageShowEvent.persisted}); 26 }; 27 </script> 28 </head> 29 <body> 30 </body> 31 </html>