/    Sign up×
Community /Pin to ProfileBookmark

I am trying to write a small routine that will open several pages. I have ‘copied’ the code from ‘Learn javascript in 21 days’, at least I think I have copied it, but cannot get it to work. I have tried to simplify it to get started but I do not appear to be calling the routine.

I’d be grateful if someone could show me where I have gone wrong.

TIA
Code is below.

<html>
<head>
<title>MTL Pages</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=”javascript” type=”text/javascript”>
<!–
function OpenIt(currentform)
{
var pfx=”http://”
var tgt=”_blank”
var nameArray = new Array();
var urlArray = new Array();
nameArray[0] = “sabs”;
urlArray[0] = “www.ntlworld.com”;
nameArray[1] = “csa”;
urlArray[1] = “www.grc.com”;
nameArray[2] = “nexus”;
urlArray[2] = “www.bbc.co.uk”;

for (var i=0; i<nameArray.Length; i++) {
/* window.open(pfx + urlArray[i], nameArray[i], target = nameArray[i]);
*
/
window.open(“http://www.bbc.co.uk“, “test”);
alert(“Open It”);
}
}
//–>
</script>

</head>

<body bgcolor=”#FFFFFF” text=”#000000″>
<form name=”form1″>
<p><input type=”button” name=”OpenWin” value=”Open”
onclick=”OpenIt(this.form)”></p>
</form>
</body>
</html>

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@JonaMay 09.2004 — [font=arial]I've taken the liberty to correct the HTML errors as well.[/font]

[font=monospace]

<!DOCTYPE html

&nbsp; &nbsp; &nbsp; &nbsp; PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

&nbsp; &nbsp; &nbsp; &nbsp; "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<html>

<head>

<title>MTL Pages</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script type="text/javascript">

//<![CDATA[

function OpenIt()

{

var pfx="http://"

var tgt="_blank"

var nameArray = new Array();

var urlArray = new Array();

nameArray[0] = "sabs";

urlArray[0] = "www.ntlworld.com";

nameArray[1] = "csa";

urlArray[1] = "www.grc.com";

nameArray[2] = "nexus";

urlArray[2] = "www.bbc.co.uk";

for (var i=0; i<nameArray.Length; i++) {

window.open(pfx + urlArray[i], nameArray[i], 'target='+nameArray[i]);

}

}

//]]>

</script>

</head>

<body>

<script type="text/javascript">

//<![CDATA[

/* Use JavaScript to generate the form button, since non-JavaScript users will have no use for it. */

document.write('<form name="form1" action="">');

document.write('<p><input type="button" name="OpenWin" value="Open" onclick="OpenIt()" /></p>');

document.write('</form>');

//]]>

</script>

<noscript><p>This page contains code for a JavaScript-only application; please enable JavaScript to view this page.

</p></noscript>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@David_HarrisonMay 09.2004 — Four small points Jona, you've used XML comments with an HTML 4.01 DTD.

//<![CDATA[

//]]>

Why have you not used a full DTD?

You've not got an action in the form tag.

If you don't post in [code] tags you get spaces at the end of each line.

My two pence.

gasman - Why do you want a script to open 3 pop-ups at once?
Copy linkTweet thisAlerts:
@JonaMay 09.2004 — [font=arial]He's trying to learn, I forgot which DTD I used, I just put something in, I admit I made some mistakes, and I hate to use the code tag; you try to be a babysitter and a programmer at the same time. ? [/font]
Copy linkTweet thisAlerts:
@David_HarrisonMay 09.2004 — I can't stand children. :mad:
Copy linkTweet thisAlerts:
@JonaMay 09.2004 — [font=arial]I love kids, but babysitting my own younger brothers is a task I don't believe I should be forced to tend to... Anyway, I edited my post. ? [/font]
Copy linkTweet thisAlerts:
@gasmanauthorMay 09.2004 — [i]Originally posted by lavalamp [/i]

gasman - Why do you want a script to open 3 pop-ups at once? [/B][/QUOTE]


At work we have to open about 5 web pages, sometimes more. The majority of the apps are web based.

It is for my benefit not anyone else yet. When I get it working I will give it to the rest of the team if they want it.

I was looking for someone to tell me where I had gone wrong, not to correct my code.
Copy linkTweet thisAlerts:
@gasmanauthorMay 09.2004 — Jona,

I cut and pasted your code. That does not work either. I do not get the warning message, but I do get the button.

I can see you amended the target syntax, but it still does not appear to call the function.
Copy linkTweet thisAlerts:
@gasmanauthorMay 09.2004 — Found it.

I had nameArray.Length and it should be nameArray.length.

Is there a way now to cycle through the open windows(there are going to be more than 3) and close them at the end of the shift.?

TIA
Copy linkTweet thisAlerts:
@David_HarrisonMay 09.2004 — What shift?
Copy linkTweet thisAlerts:
@gasmanauthorMay 09.2004 — Sorry, bad phrasing.

I meant at the end of my work shift, when going home.

I've found out a way to do it anyway.

Thanks to everyone for the replies
×

Success!

Help @gasman 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.11,
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,
)...