Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script

Status
Not open for further replies.

pau141

Technical User
Joined
Jan 20, 2003
Messages
3
Location
US
Can you spot the problem?

The first script runs with no problem. However, the second delayed script does not. Both are set to run wnen the page closes...onUnload.

<head>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-us&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<title></title>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
var exit=true;
function leave() {
if (exit)
window.open('}
// End -->
</SCRIPT>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
closetime = 0; // Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds

function Start(URL, WIDTH, HEIGHT) {
windowprops = &quot;left=50,top=50,width=&quot; + WIDTH + &quot;,height=&quot; + HEIGHT;
preview = window.open(URL, &quot;preview&quot;, windowprops);
if (closetime) setTimeout(&quot;preview.close();&quot;, closetime*1000);
}

function doPopup() {
url = &quot;width = 267; // width of window in pixels
height = 103; // height of window in pixels
delay = 2; // time in seconds before popup opens
timer = setTimeout(&quot;Start(url, width, height)&quot;, delay*1000);
}
// End -->
</script>



</head>


<body bgcolor=&quot;#FFFFFF&quot; onUnload=&quot;leave()&quot; &quot;doPopup();&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot;>
 
this line is not correct:
<body bgcolor=&quot;#FFFFFF&quot; onUnload=&quot;leave()&quot; &quot;doPopup();&quot; leftmargin
should be:
<body bgcolor=&quot;#FFFFFF&quot; onUnload=&quot;leave();doPopup();&quot; leftmargin

I am not sure the setTimeout does anything because the function finishes and the page unloads before the Start can be executed.
 
Yes I see, what would be the correct setTimeout, to have the delayed script run properly on a page Unload?
 
So when you leave the page you want to have a popup come up with a delay.
This is not possible because you have allready left the page and when you have left it no javascript is executed anymore.
<script>
function onUnload(){
alert('leaving the page');
setTimeout(&quot;allready left the page);&quot;,500);
}
</script>
<body onunload=&quot;onUnload()&quot;>
</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top