0

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 requirements for the web app we are making is to have a certain page (daily sales report) open once the user presses X on the browser, this is a local file only ans aside from using window.onbeforeunload = window.open("dailyreport.html"); , which opens the page every time I do anything (click links etc) I have hit a brick wall.

Also i forgot to mention we are not allowd to use JSON or jquery at all... sucks but thats what the bosses want

Thanks guys Steve

user2397654
  • 45
  • 1
  • 8

2 Answers2

0

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.

Community
  • 1
  • 1
ose
  • 4,065
  • 2
  • 24
  • 40
  • well i hope they dont, i have written this page using chrome and created a redirect page for all other browsers saying Unsupported, please download Chrome!" I will have a try with this and let you know, thanks!! – user2397654 May 19 '13 at 14:16
-1

Try this JSFIDDLE

window.onload = function(){
        var as = 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");}
}
Anoop
  • 23,044
  • 10
  • 62
  • 76
  • hey, thanks for the quick reply, while that does open a new window, it still opens it if i click any links within the page as well, not when it closes. Thanks though – user2397654 May 19 '13 at 14:14
  • @user2397654 as far as I know there is no way to differentiate between navigation and page close. – Anoop May 19 '13 at 14:16
  • in that case, would i be able to have an event come up that displays all the data in the other page? I understand i would need to link to the data which is nothing to major, just time consuming, but can event windows handle any data? I figured having the info in a confirmation window would be sufficient – user2397654 May 19 '13 at 14:20
  • @user2397654 now I am preventing window.open on link click. try this – Anoop May 19 '13 at 14:24
  • that has stopped the window from opening when i click links, but still nothing when i close the window/tab, does the location of the script matter? – user2397654 May 19 '13 at 14:27
  • @user2397654 It is working for me. do your all pages has this code. I mean after click on link browser will load new page. does new page has this code? – Anoop May 19 '13 at 14:33
  • yeah it shows up in my code, i put it in the header. It doesnt seem to be doing anything that i can see, if i close the window it just closes, no popup warnings, nothing at all. – user2397654 May 19 '13 at 14:41
  • are you overriding window.onload function? – Anoop May 19 '13 at 14:44
  • no nothing like that, does it make a difference that i am using chrome? – user2397654 May 19 '13 at 14:50