I have tried e.preventdefault() and e.stoppropagation(), but. Window.onbeforeunload = function(e) { if(refreshmode == 1){ return; }else{ // don't do it!