Skip to content Skip to sidebar Skip to footer

Opening Another Window In Javascript When User Presses X On Browser

I understand this question has been asked and either answered or rejected before, but i promise i have a reasonably legit reason for asking. I am doing a Uni course and one of the

Solution 1:

You are looking for the windown.onclose event.

As from here

However, note that this is not supported by all browsers. If it is for a uni project you might be able to get away with it though if your requirements don't specify across-the-board browser compatibility.

Solution 2:

Try this JSFIDDLE

window.onload = function(){
        varas = document.getElementsByTagName("a");
    var linkClicked = false;
    for(i=0;i<as.length; i++){
        as[i].onclick = function(){

            linkClicked= true;
        }
    }

    window.onbeforeunload = function(){!linkClicked && window.open("dailyreport.html");}
}

Post a Comment for "Opening Another Window In Javascript When User Presses X On Browser"