/    Sign up×
Community /Pin to ProfileBookmark

Problem when combining two executable script

Each of these script execute fine on their own. But once I combine them as shown, only the first script will execute.

My goal is to have a “popup immediately” on a page close and then a “delayed popup” when the same page closes.

#1)
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
var exit=true;
function leave() {
if (exit)
window.open(‘http://www.anypage.htm’,”,’toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,height=460,width=700′);
}
// End –>
</SCRIPT>

</head>

<body bgcolor=”#FFFFFF” onUnload=”leave()” leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>

#)2

<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
closetime = 0;
// Close window after __ number of seconds?
// 0 = do not close, anything else = number of seconds
function Start(URL, WIDTH, HEIGHT)
{windowprops = “left=50,top=50,width=” + WIDTH + “,height=” + HEIGHT;preview = window.open(URL, “preview”, windowprops);
if (closetime) setTimeout(“preview.close();”, closetime*1000);}
function doPopup() {url = “http://any page.html”;width = 267;

// width of window in pixels
height = 103;
// height of window in pixels
delay = 20;

// time in seconds before popup opens
timer = setTimeout(“Start(url, width, height)”, delay*
1000);}
// End
–>
</script>

<body OnLoad=”doPopup();”>

Combining the script to execute on page unload only.

<html>

<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<meta http-equiv=”Content-Language” content=”en-us”>
<meta name=”GENERATOR” content=”Microsoft FrontPage 4.0″>
<meta name=”ProgId” content=”FrontPage.Editor.Document”>
<title></title>
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
var exit=true;
function leave() {
if (exit)
window.open(‘http://www.anypage.htm’,”,’toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,height=460,width=700′);
}
// End –>
</SCRIPT>

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

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

function doPopup() {
url = “http://www.anypage.html“;
width = 267; // width of window in pixels
height = 103; // height of window in pixels
delay = 2; // time in seconds before popup opens
timer = setTimeout(“Start(url, width, height)”, delay*1000);
}
// End –>
</script>

</head>

<body bgcolor=”#FFFFFF” onUnload=”leave();doPopup();” leftmargin=”0″ topmargin=”0″ marginwidth=”0″ marginheight=”0″>

have also tried this line in the combination script to no avail.
timer = setTimeout(“Start(” + url + “, ” + width + “, ” + height + “)”, delay*1000);

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@jdaviaJan 22.2003 — I am assumming that in a certain set time, you want to open another window, and for that window to close at another set time.

If so you need to put code in each window telling each what it should do.

Let us know how you are doing.
Copy linkTweet thisAlerts:
@pau141authorJan 22.2003 — [i]Originally posted by jdavia [/i]

[B]I am assumming that in a certain set time, you want to open another window, and for that window to close at another set time.

If so you need to put code in each window telling each what it should do.

Let us know how you are doing. [/B]
[/QUOTE]
:?

My goal is to have a "popup immediately" on a page close and then a "delayed popup" when the same page closes.

Can't seem to get it.
Copy linkTweet thisAlerts:
@jdaviaJan 22.2003 — My goal is to have a "popup immediately" on a page close and then a "delayed popup" when the same page closes.[/QUOTE]
You also say:
Each of these script execute fine on their own. But once I combine them as shown only the first script will execute. [/QUOTE]

This tells me that the OnUnLoad event handler works but is burdened with a task that it cannot complete, because the first command closed the document leaving the second command looking for objects and values that no longer exist. Your best defense is to keep the event handler processing ato a minimum.

Which is why I suggested putting code in the other window to carry out the second command for the delayed window to open.
Copy linkTweet thisAlerts:
@pau141authorJan 23.2003 — got it . Put second script into first script html page.

Works fine.

Mahalo
×

Success!

Help @pau141 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...