Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
戻るとかでページを離脱する際の 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

This comment has been minimized.

Copy link
Owner Author

@wtnabe 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