Last active
March 8, 2020 18:04
-
-
Save frydlewicz/e949667521a1217bd450b20bef4dcfb9 to your computer and use it in GitHub Desktop.
Call function when user wants to leave the website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(g,e,c){if(typeof g!="function"){return}var d=false;var f=0;var b=function(){var h=(new Date).getTime();if(d&&(f==0||e&&h-f>c)){document.removeEventListener("mouseleave",b);f=h;g()}};var a=function(j){var h=innerHeight/10;var i=j.movementY;var k=j.clientY;if(i<0&&k<h){d=true;document.addEventListener("mouseleave",b)}else{document.removeEventListener("mouseleave",b);d=false}};document.addEventListener("mousemove",a)})( | |
function () { // callback function | |
alert("Do not leave!") | |
}, | |
true, // repeat calling | |
5000 // interval in milliseconds | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment