/    Sign up×
Community /Pin to ProfileBookmark

opening multiple urls using window.open function

Greetings:
I’m trying to creating a function which allows me to enter the url link in the body of the code when calling the window.open function.

Currently my code is written as followed…

[CODE]

<SCRIPT language=”JavaScript1.2″>
function poponload()
{
testwindow= window.open (“”, “mywindow”,”location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550″);
testwindow.moveTo(25,40);
}
</SCRIPT>

<body style=”background: #39275B;
background-attachment: fixed;
background-repeat: no-repeat;
background-position: center;
link=”white” vlink=”red” alink=”white””>

<font face=”Verdana, Arial, Helvetica, sans-serif” size=”2″ color=”#FFFFFF”>
<li type=”circle”>
[COLOR=”Red”]<a href=”javascript: poponload()” class=”linkw”>Application</a>[/COLOR]
</font></li>

</body>
</html>

[/CODE]:confused::confused::confused::confused:

I would like to enter a different url link each time i call the function
Like the example below
[CODE]

<a href=”javascript: poponload(http://www.google.com)” class=”linkw”>Application</a>

<a href=”javascript: poponload(/secure/mlu/Henderson.pdf)” class=”linkw”>Application</a>

<a href=”javascript: poponload(/secure/ucla/And.html)” class=”linkw”>Application</a>

<a href=”javascript: poponload(http://www.webdeveloper.com)” class=”linkw”>Application</a>

[/CODE]

Any help is greatly appreciated

to post a comment
JavaScript

20 Comments(s)

Copy linkTweet thisAlerts:
@MrNobodyNov 17.2008 — Just put the different URL's inside of single quotes and do this:
[CODE]function poponload(url)
{
var testwindow = window.open (url, "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}[/CODE]
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 17.2008 — Thanks but i receive a syntax error when i do the following...

[CODE]
<SCRIPT language="JavaScript1.2">
function poponload(url)
{
var testwindow = window.open (url, "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}
</SCRIPT>

<body style="background: #39275B;
background-attachment: fixed;
background-repeat: no-repeat;

background-position: center;
link="white" vlink="red" alink="white"">


<font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">
<li type="circle">
<a href="javascript: poponload('http://www.google.com')" class="linkw">Application</a>

<a href="javascript: poponload('/secure/mlu/Henderson.pdf')" class="linkw">Application</a>

<a href="javascript: poponload('/secure/ucla/And.html')" class="linkw">Application</a>

<a href="javascript: poponload('http://www.webdeveloper.com')" class="linkw">Application</a>

</font></li>

</body>
</html>


[/CODE]
Copy linkTweet thisAlerts:
@MrNobodyNov 17.2008 — The error is probably in your [B]moveTo[/B] line. Remove that line to find out.
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 17.2008 — Thanks but the error tell me the line number which is ..

<a href="javascript: poponload('http://www.google.com')" class="linkw">Application</a>

When i added the single quotes and the url, i get the error. If i leave it blank the code works but opens a blank page
Copy linkTweet thisAlerts:
@MrNobodyNov 17.2008 — Thanks but the error tell me the line number which is ..

<a href="javascript: poponload('http://www.google.com')" class="linkw">Application</a>[/QUOTE]

With single quotes is correct syntax. Are you using server-side code to build that HTML line? If so, then the problem is in the server-side which you are not showing. If not, then post a link to the full live page so I can try it out for myself.
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 17.2008 — [CODE]
<?php
session_start();
?>




<HTML>


<head>
<title>me</title>







<style type="text/css">
.linkw{color:#FFFFF;}
</style>



</head>

<SCRIPT language="JavaScript1.2">
function poponload(url)
{
var testwindow= window.open ('', "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}
</SCRIPT>


<body style="background: #39275B;
background-attachment: fixed;
background-repeat: no-repeat;

background-position: center;
link="white" vlink="red" alink="white"">


<?php

// check session variable

if (isset($_SESSION['valid_user']))
{

echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: poponload([COLOR="Red"]want to add url here[/COLOR])" class="linkw">Application</a>';
echo '</td></tr>';

echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: poponload([COLOR="red"]2nd url here[/COLOR])" class="linkw">Application</a>';
echo '</td></tr>';


echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: poponload([COLOR="red"]3rd url here[/COLOR])" class="linkw">Application</a>';
echo '</td></tr>';


echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: poponload([COLOR="red"]4th url here[/COLOR])" class="linkw">Application</a>';
echo '</td></tr>';





}
else
{
echo '<p>You are not logged in.</p>';
echo '<p>Only logged in members may view information on this page.</p>';
echo '<a href="login_me.php" class="linkw">Back to main page please</a>';

}


?>


</body>
</html>



[/CODE]




Right now there is no url inside poponload()......and the code give a blank popup window. But when i add the url with single quotes poponload('/secure/me/me.pdf') or poponload(http://www.google.com) i receive a syntax error on this line stating that a "," or a ";" is missing
Copy linkTweet thisAlerts:
@MrNobodyNov 17.2008 — Yep, the error was in your server-side code. Change this:
echo '&lt;a href="javascript: poponload([COLOR="Red"]want to add url here[/COLOR])" class="linkw"&gt;Application&lt;/a&gt;';
to this:
echo '&lt;a href="javascript: poponload([COLOR="Red"]'want to add url here'[/COLOR])" class="linkw"&gt;Application&lt;/a&gt;';
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 18.2008 — Thanks, although it resolved the error, it now brings up a blank page...as if it totally ignores whats inside the parentheses
Copy linkTweet thisAlerts:
@MrNobodyNov 18.2008 — So what does the generated HTML at the client look like now?
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 18.2008 — I still receive a blank html page. I'm not sure what i'm missing yet i know i can been executed.
Copy linkTweet thisAlerts:
@MrNobodyNov 18.2008 — No, the generated HTML *before* you click the link.
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 19.2008 — No, the generated HTML *before* you click the link.[/QUOTE]

I just created an html file (omitted the php file) with just the javascript function above and the issue still exist. i really dont think it has anything to do with the php coding because im still unable to insert a link and get the website. All your help is very appreciated. If i may ask you to create an html file with that javascript function and attempt to insert a link in the body of the file where u are calling the function and see if that website is executed. thanks again
Copy linkTweet thisAlerts:
@MrNobodyNov 19.2008 — I noticed in your function that you are missing a parameter. This is what I posted for you to use. Note the part in [COLOR="Red"]red[/COLOR]:
[CODE]function poponload(url)
{
var testwindow = window.open ([COLOR="Red"]url[/COLOR], "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}[/CODE]
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 19.2008 — I noticed in your function that you are missing a parameter. This is what I posted for you to use. Note the part in [COLOR="Red"]red[/COLOR]:
[CODE]function poponload(url)
{
var testwindow = window.open ([COLOR="Red"]url[/COLOR], "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}[/CODE]
[/QUOTE]


i have that in my code
Copy linkTweet thisAlerts:
@MrNobodyNov 19.2008 — Post #7 above was missing it so I wondered... had to make sure.
Copy linkTweet thisAlerts:
@MrNobodyNov 19.2008 — I do it this way so that if JavaScript is disabled, the link still works:
[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Popup Links</title>
<script type="text/javascript">
<!--//
function poponload(url, tgt)
{
var testwindow = window.open (url, tgt, "location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
// testwindow.moveTo(25,40);
return false;
}
//-->
</script>
</head>

<body>

<p><a href="http://www.google.com/" target="_blank"
onclick="return poponload(this.href, this.target)">Google</a></p>
<p><a href="http://www.yahoo.com/" target="_blank"
onclick="return poponload(this.href, this.target)">Yahoo</a></p>

</body>
</html>[/code]

Your [B]moveTo[/B] is commented out because it was causing an error -- as I suggested several posts ago.
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 20.2008 — I noticed in your function that you are missing a parameter. This is what I posted for you to use. Note the part in [COLOR="Red"]red[/COLOR]:
[CODE]function poponload(url)
{
var testwindow = window.open ([COLOR="Red"]url[/COLOR], "mywindow","location=no,status=0,scrollbars=0,menubar=0,resizable=0,toolbar=0,directories=0,width=750,height=550");
testwindow.moveTo(25,40);
}[/CODE]
[/QUOTE]


ok. I realized now that it may be my php syntax. I was successful in launching the website without my php coding. If you have any suggestions for the above php script, please post. Meanwhile i will be researching php syntax. Thanks for all your help and future help. O. Im using PHP version 4.4.8
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 20.2008 — Yes....ok i got it now!!! (with your help of course)... below is the code i used

Thanks again for not giving up on me

[code=php]

<?php
session_start();
?>




<HTML>


<head>
<title>popup</title>


</head>

<script type="text/javascript">
<!--
function popup(url)
{
var width = 900;
var height = 800;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
newwin=window.open(url,'windowname5', params);
if (window.focus) {newwin.focus()}
return false;
}
// -->
</script>

<body>

<?php

// check session variable

if (isset($_SESSION['valid_user']))
{

echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: void()" onclick="popup('http://www.mysite.com/secure/me.pdf')" class="linkw">Application</a>';
echo '</td></tr>';


echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: void()" onclick="popup('http://www.google.com/ig')" class="linkw">Application</a>';
echo '</td></tr>';



echo '<tr align="center" bgcolor="#39275B"><td colspan="3">';
echo '<a href="javascript: void()" onclick="popup('defaultpage.php')" class="linkw">Application</a>';
echo '</td></tr>';




}
else
{
echo '<p>You are not logged in.</p>';
echo '<p>Only logged in members may view information on this page.</p>';
echo '<a href="h7.php" class="linkw">Back to main page please</a>';

}


?>
[/code]


Just one last question....What is the reason for adding the comments (<!-- ... -->) within the javascript....It works with and without so why use it?
Copy linkTweet thisAlerts:
@MrNobodyNov 20.2008 — It used to be a requirement in case the browser didn't support JavaScript -- that way, it would be commented out and not cause errors during page load. Browsers nowadays should be smart enough to skip the JavaScript code even if they don't support it. But, ya never know. ?
Copy linkTweet thisAlerts:
@AHendersonWebDeauthorNov 20.2008 — Thanks for all your help!!
×

Success!

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