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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!!
-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");} } 

9 Comments

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 as far as I know there is no way to differentiate between navigation and page close.
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 now I am preventing window.open on link click. try this
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?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.