Rewriting the question -
I am trying to make a page on which if user leave the page (either to other link/website or closing window/tab) I want to show the onbeforeunload
handeler saying we have a great offer for you?
and if user choose to leave the page
it should do the normal propogation but if he choose to stay on the page
I need him to redirect it to offer page redirection is important, no compromise
. For testing lets redirect to google.com
I made a program as follows -
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.onunload = function(e) {
clearTimeout(a);
};
}
window.onload = load;
but the problem is that if he click on the link to yahoo.com
and choose to leave the page
he is not going to yahoo but to google instead :(
Help Me !! Thanks in Advance
here how you can test because onbeforeunload does not work on iframe well