Skip to content

Commit

Permalink
Add button to clear the beforeunload listener
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 1, 2019
1 parent 3e34432 commit a26455b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions testcases/cancel-beforeunload.html
Expand Up @@ -6,11 +6,12 @@
<head>
<meta charset="UTF-8">
<script type="application/javascript"><!--
window.addEventListener('beforeunload', function(event) {
function onBeforeUnload(event) {
console.log('beforeunload');
event.preventDefault();
event.returnValue = '';
});
}
window.addEventListener('beforeunload', onBeforeUnload);
console.log('beforeunload listener is registered.');

function openTabs(url, count) {
Expand All @@ -23,6 +24,10 @@
</head>
<body>
<p>This page should show a confirmation before closed or reloaded.</p>
<p><button onclick="window.removeEventListener('beforeunload', onBeforeUnload)"
onkeypress="if (event.key == 'Enter') window.removeEventListener('beforeunload', onBeforeUnload);"
>Clear unload listener</button></p>
<hr>
<p><button data-count="5"
data-url="about:blank"
onclick="openTabs(this.dataset.url, this.dataset.count)"
Expand Down

0 comments on commit a26455b

Please sign in to comment.