Skip to content

Instantly share code, notes, and snippets.

@8ctopotamus
Last active January 18, 2018 16:52
Show Gist options
  • Save 8ctopotamus/97927bcce2dcf46b6156b586e2333011 to your computer and use it in GitHub Desktop.
Save 8ctopotamus/97927bcce2dcf46b6156b586e2333011 to your computer and use it in GitHub Desktop.
Quick-escape functionality
(function() {
// the ESC button on the page
var quickESCButton = document.getElementById('quick-esc')
function getAway() {
// open new tab with innocent site
window.open("http://weather.com", "_newtab")
// replace current site with another benign site
window.location.replace('http://google.com')
}
// automatically leave site if page left idle for a long time
function idleLeaveSiteTimer() {
var t
window.onload = resetTimer
window.onmousemove = resetTimer
window.onmousedown = resetTimer // catches touchscreen presses
window.onclick = resetTimer // catches touchpad clicks
window.onscroll = resetTimer // catches scrolling with arrow keys
window.onkeypress = resetTimer
function resetTimer() {
clearTimeout(t)
t = setTimeout(getAway, 300000) // time is in milliseconds (5 min)
}
}
// keyboard ESC
document.addEventListener('keyup', function(e) {
if (e.keyCode == 27) { // esc key
getAway()
}
})
quickESCButton.addEventListener('click', function(e) {
getAway()
})
idleLeaveSiteTimer()
})()
@8ctopotamus
Copy link
Author

The back button was still working in chrome and edge. Check these out if you absolutely need to disable the back button:

The solution of adding window.history.forward(1); to my script worked for me! It just redirects you to a new blank tab.

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