Prevent page from going anywhere
While working on an old fashioned "traditional" website (not a web app), I often had to inspect/debug pages that were automatically redirecting themselves somewhere else without having a way to prevent them from doing so in the code.
So I came up with something in the browser that will prevent them from going away.
(function() {
var blocked = false;
var interval = window.setInterval(function() {
if (blocked) {
document.location.href = document.location.href + '#' + Math.random();
blocked = false;
}
}, 100);
window.addEventListener('beforeunload', function () {
blocked = true;
}, false);
window.addEventListener('unload', function () {
blocked = false;
}, false);
})();
The page will never leave.
Written by Ricardo Magalhães
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Debug
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#