beforeunload-canceling-1.html (838B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Support page for beforeunload-canceling.html</title> 4 5 <h1>If this goes away, it navigated</h1> 6 7 <script> 8 "use strict"; 9 10 window.runTest = (t, { valueToReturn, expectCancelation, setReturnValue, expectedReturnValue, cancel }) => { 11 window.onbeforeunload = t.step_func(e => { 12 if (cancel) { 13 e.preventDefault(); 14 } 15 16 if (setReturnValue !== undefined) { 17 e.returnValue = setReturnValue; 18 } 19 20 return valueToReturn; 21 }); 22 23 const listener = t.step_func(e => { 24 top.assert_equals(e.defaultPrevented, expectCancelation, "canceled"); 25 top.assert_equals(e.returnValue, expectedReturnValue, "returnValue"); 26 window.onbeforeunload = null; 27 28 t.done(); 29 }); 30 31 window.addEventListener("beforeunload", listener); 32 33 window.location.href = "about:blank"; 34 }; 35 </script>