Question

So I'm looking to display a window when the user tries to leave a page, but I'm having quite a bit of trouble.

<script type="text/javascript">
window.onunload = openWin()
</script>

When I put the above into the Head of the html file the function fires, but upon the page LOADING, not when it closes. This happens in IE8, Opera 12 and Chrome 18. (The latter two detect it as a pop-up and block it accordingly)

It's not for any nefarious purpose mind you, I'm just trying to display a summary of orders placed throughout the day; The above function is available at any time via a button, but I also need it to display when the page is closed.

Was it helpful?

Solution

You are calling the function at the time of assignment. What you want to do is assign the function itself to window.onunload. Try:

window.onunload = openWin;

without the () parentheses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top