PDA

View Full Version : Automatic Timed Self-Closing Popup Window


Umesh
01-08-2003, 01:37 PM
Hi,

I want to use this code to open a pop-up and automatically close it after 1 second only when a customer exits my website. Currently it is working but the pop-up also comes when you click on to a link within the website. I need to stop this and only have it come up on exit.

This is the code in the main page:

<script language="JavaScript">
<!--
ok=1
function open_on_departure(url,name)
{
if (ok)
popupWin = window.open('http://www.foneandsurf.com/acatalog/closepop.html','Closing_Down', ' width=350,height=100,')
}
// -->
</script>

onUnload="open_on_departure()

==============================================
This is the loading page code:

<script language="JavaScript">
// (C) 2003 www.foneandsurf.com.com
// http://www.foneandsurf.com.com
// Free for all users, but leave in this header

var howLong = 1000;

t = null;
function closeMe(){
t = setTimeout("self.close()",howLong);
}

</script>

<body onload="closeMe();self.focus()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="#FFFFFF"><font color="#00009c" size="6" face="Arial, Helvetica, sans-serif">Thank
you for visiting</font><br>
<br>
<font color="#00009c" size="2" face="Arial, Helvetica, sans-serif">Please call again</font></td>
</tr>
</table>

=============================================

Can someone help me to get this code right.

To see more of the code please log on www.foneandsurf.com

chrismiceli
01-08-2003, 01:44 PM
i don't see anything wront with that script except there isn't a quote after the onload function, but that is probably a copy and paste error. could you show us an example of one of your links which opens in a popup?-

Umesh
01-08-2003, 01:46 PM
The best way to see what I mean is to go to me web site and click on a few links and then it would be self explanitry to see whats wrong.

www.foneandsurf.com

Umesh
01-08-2003, 02:05 PM
Is there anyone that could help me with code urgently please.

All help would br very much appreciated.

Thank you

arnyinc
01-08-2003, 05:45 PM
It's working correctly, but unless you have a logout button or some way of detecting when the user actually leaves your site, you can't really do this.

Umesh
01-08-2003, 06:07 PM
Its cant be working properly, simply reason is that i have a ecommerce website, into that i have different sections which a customer can go into. They dont exit the website to go from one section to another. This command only needs to work when someone presses the close button at the top of the window.

Loyds Tsb motoring direct web page have this function working properly. I know it can be done the code needs to be adjusted for that purpose.

Any further help would be much appreciated.

Please log on to www.foneandsurf.com to see an example of the error I am getting.

arnyinc
01-08-2003, 07:04 PM
It's a lot of administrative overhead, but this is worth a try. Basically, you have to add the onload and onUnload events to every body tag. They add onClick="leaving=false" to any link you don't want to trigger your popup. This will trigger the popup when someone leaves your site or clicks a link that you doesn't set the "leaving" variable to false.

<html>

<body onLoad="leaving=true" onUnload="if (leaving) window.open('your_popup.htm');">

<a href="something.htm" onClick="leaving=false">link 1</a>
<a href="http://mydomain/mylink.htm" onClick="leaving=false">link 2</a>
<a href="http://somewhereelse/notyoursite.htm">external link</a>

</body>

</html>

glenngv
01-09-2003, 03:40 AM
there is a solution but unfortunately in IE only.
see my suggestion in these threads:
http://codingforums.com/showthread.php?s=&threadid=6823
http://codingforums.com/showthread.php?s=&threadid=8563