Please check my code in Chrome Browser, if you hit refresh you will be prompted with 2 options.
- Leave This Page and
- Stay on This Page>
use a timer to listening for change variable :
var vals=0;
function displayMsg() {
alert('my text..');
}
window.onbeforeunload = function evens(evt) {
var message = 'Please Stay on this page and we will show you a secret text.';
if (typeof evt == 'undefined') {
evt = window.event;
}
timedCount();
vals++;
if (evt) {
evt.returnValue = message ;
return message ;
}
trace(evt);
}
function timedCount()
{
t=setTimeout("timedCount()",100);
if(vals>0)
{
displayMsg();
clearTimeout(t);
}
}