Here is My code : but it redirect on both click stay on page and leave page . I need to redirect user on specific URL click on leave page .
<script>
var stayonthis = true;
var a;
function load() {
window.onbeforeunload = function(e) {
if(stayonthis){
a = setTimeout('window.location.href="http://google.com";',100);
stayonthis = false;
return "Do you really want to leave now?";
}
else {
clearTimeout(a);
}
};
}
window.onload = load;
</script>