prevent-back
v0.0.1
Published
Prevent vistor go back to previous page
Downloads
242
Maintainers
Readme
prevent-back
Prevent vistor go back to previous page
Demo
Install
yarn add prevent-back
Usage
<script type="module">
import preventBack from 'https://unpkg.com/prevent-back?module'
preventBack((stay, leave) => {
const confirmedToLeave = confirm('Are you sure you want leave?')
if (confirmedToLeave) {
leave()
} else {
stay()
}
})
</script>
API
import preventBack, {stay, leave} from 'prevent-back'
preventBack(onAttemptToLeave)
import preventBack from 'prevent-back'
preventBack((stay, leave) => {
const confirmedToLeave = confirm('Are you sure you want leave?')
if (confirmedToLeave) {
leave()
} else {
stay()
}
})
stay
and leave
import preventBack, {stay, leave} from 'prevent-back'
document.querySelector('#js-stay-button').addEventListener('click', stay)
document.querySelector('#js-leave-button').addEventListener('click', leave)
preventBack(() => {
document.querySelector('#js-dialog').showModal()
})