Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Created April 29, 2021 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/b14e680c436ead5602b106966eefddd4 to your computer and use it in GitHub Desktop.
Save wtnabe/b14e680c436ead5602b106966eefddd4 to your computer and use it in GitHub Desktop.
戻るとかでページを離脱する際の event を捕捉できるか、実験
<html>
<head>
<meta name="viewport" content="width=device-width">
</head>
<body>
<script type="text/javascript" src="https://unpkg.com/page-lifecycle@0.1.2/dist/lifecycle.es5.js"></script>
<script type="text/javascript">
lifecycle.addEventListener('statechange', (event) => {
console.log('statchange')
console.log(event)
// cannot stop
event.originalEvent.returnValue = false
event.originalEvent.preventDefault()
return false
})
</script>
</body>
</html>
@wtnabe
Copy link
Author

wtnabe commented Apr 29, 2021

see

捕捉はできるけど window.beforeunload のように cancel することはできない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment