Forum Moderators: open
What I need to do is open a small window but only when the original window is closed. What I have now is opening the small window whenever the current page is left, i.e. if they click on a link and go to another page the small window still comes up. I only want it to come up when the user closes the browser.
Does this make sense?
Thanks for your time!
I did finally find a couple of posts that had a similar work-around by adding some script to each link so that clicking on the links wouldn't trigger the new window, but that approach is very messy for this site (quite a few links) and it doesn't work if a user hits the forward or back buttons or uses the history bar to navigate.
If anyone has another idea I would love to hear it!
Thanks.
1. put this code below between your <head></head> tag.
<!--
Code By "CodeFreak" Cloud - codefreak.proboards19.com - 2003
You may leave this part of code intact to show your gratitude or remove it
-->
<script language=javascript>
function popitup()
{
window.open("poppedup.html", "popup", 'width=400,height=200,scrollbars=yes');
}
</script>
You can change the popup window attribute just as you wish. "poppedup.html" is your popup windows page, you can change it as you wish.
2. add this to your body tag
<body onunload="popitup();">
and you are done :)
I tried that approach earlier. It didn't achieve what exactly what I was after.
If I close the window it would certainly open the pop-up. However, it would also do it if I simply went to a new page.
Onunload will run the script whenever the document is unloaded and doesn't differentiate between when a window is closed or when a visitor simply leaves the page.
I needed the pop-up to fire ONLY when the original window was specifically closed and to NOT fire if the visitor just left the page.
and there is no other way to detect whether if the user click the close button or simply change the url.
The only way I can think of is have a link or button that when the user click on it, the browser will close down, thus a pop up will appear e.g <a href=# onclick="popitup(); window.close();">Close the Window</a>. Other than that, I think it won't possible
<script type="text/javascript" language="javascript">
onunload = function() {
if ((window.event.clientX<0) && (window.event.clientY<0))
alert('Window was closed!');
}
</script>