Click to See Complete Forum and Search --> : Opening a new window
mdanan
01-21-2003, 03:09 PM
I have a page with a lot of links in it, and I'm opening each link with a new window. The code I'm currently using is working fine, the only problem is that I don't know where I can put the window features at, like:
toolbars=no, menubar=no, scroolbars=no, width=300, and height=300
Anyhow, here's a sample of the code I'm using:
<head>
<!--
function newwin(target)
{
if (target) where = "_blank";
else where = "_blank";
for var i=0; i<=(document.links.length-1); i++)
{
document.links[i].target = where;
}
}
// -->
</head>
<body>
<a href="one.htm" onclick="newwin(target)">one</a>
<a href="two.htm" onclick="newwin(target)">two</a>
</body>
If you know of another way of opening new windows, provided that there are numerous links on it and that it has to be redirected to a different page than the other, I would really really appreciate it.
Please help...
Charles
01-21-2003, 03:24 PM
If you want to specify a new window for one link then use:
<a href="http://www.w3.org/" onclick="window.open(this.href, 'child', 'height=300,width=300'); return false">W3C</a>
But if you want to specify a new window for all of the links on a page then use:
<script type="text/javascript">
<!--
window.onload = function () {for (j=0; j<document.links.length; j++) {document.links[j].onclick = function () {window.open(this.href, 'child', 'height=300,width=300'); return false}}
// -->
</script>
ShrineDesigns
01-21-2003, 03:24 PM
try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function newWin(targ) {
for (var i = 0; i <= document.links.length-1; i++) {
if (targ == 0){
document.links[i].target = "_top";
}
else if (targ == 1){
document.links[i].target = "_blank";
}
else if (targ == 2){
document.links[i].target = "namedWin";
}
}
}
//-->
</script>
</head>
<body>
<a href="one.htm" onclick="newWin(0)">one</a> <a href="two.htm" onclick="newWin(1)">two</a>
<a href="three.htm" onclick="newWin(2)">two</a>
</body>
</html>
Charles
01-21-2003, 03:31 PM
ShrineDesigns,
Think about that piece of script. For each of those links, when said link is activated the script will walk through each link on the page and reset the target for that link. And it will not do what mdanan requested.
mdanan
01-21-2003, 03:56 PM
Charles,
Thanks so much!!! Both scripts that you gave worked beautifully, but I'm using the first one you wrote. At least I'd get to specify the window size for each link.
Thanks again!
On a note: I'd have to compliment this forum as very helpful unlike the previous site I used to go to: experts-exchange.com. Their response time was really poor that I'd even have to wait for a day just to get some help.
Again, thanks so much!!!
Originally posted by Charles
If you want to specify a new window for one link then use:
<a href="http://www.w3.org/" onclick="window.open(this.href, 'child', 'height=300,width=300'); return false">W3C</a>
But if you want to specify a new window for all of the links on a page then use:
<script type="text/javascript">
<!--
window.onload = function () {for (j=0; j<document.links.length; j++) {document.links[j].onclick = function () {window.open(this.href, 'child', 'height=300,width=300'); return false}}
// -->
</script>