Click to See Complete Forum and Search --> : window.open once again


dimamo1983
08-25-2003, 08:22 PM
i finally have a little free time on my hands and would like to learn javascript, but now I'm stuck with the basics - window.open function

I have two books on javascript. One of them says that correct syntax is window.open("address", "name", "parameters"); The other one says that I have to add config= infront of parameters: window.open("address", "name", config="parameters");
Any idea why is that? I mean both ways seem to work, but I'm just wondering...

Now moving on to the actual problem. I'm trying to open a larger-size picture in a new window whenever user clicks on my thumbnail. I don't have any problems doing it inline like:

<a href="#" onClick="window.open('images/pictures/13.jpg', 'blah', config='height=520,width=500,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no'); return false;">
<img src="images/pictures/thumbs/13.jpg" width="128" height="95" alt="13.jpg" />
</a>

or even easier by sticking onClick inside the img:

<img src="images/pictures/thumbs/20.jpg" width="128" height="83" alt="20.jpg" onClick="window.open('images/pictures/20.jpg', 'blah', config='height=520,width=500,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no'); return false;" />

however, I have many images and would like to have a function that I can call to open each one of them. Something like showPicture(url, height, width). I tried doing it, but can't get anywhere. It just doesn't do anything, just moves to the top of the pages whenever I click on a thumb. Here is what I have:
<head>
<script type="text/javascript" language="javascript">
function showPicture(url, h, w)
{
var newwindow = window.open(url, url, "height="+h+",width="+w+",toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no");
}
</script>
</head>

<body>
<a href="#" onClick="showPicture('images/pictures/45.jpg', 500,500); return false;
<img src="images/pictures/thumbs/45.jpg" width="128" height="83" alt="45.jpg" />
</a>
</body>

Anyone have any ideas what's going on? :confused:

thanks

dima

dimamo1983
08-25-2003, 08:25 PM
yes, there is a closing > for <a> tag after return false;
just did not copy it for some reason.

Charles
08-26-2003, 05:12 AM
Using JavaScript on the web is a bit problematic. 13% of users do not use it and some of those good people cannot use it because of some disability. The trick with using JavaScript is in doing no harm. That is to say, making sure that your page fails safe so that it works as well with as without JavaScript.

Take the example of a new window. For people who have pop-ups disabled or who are not using JavaScript we want the link to simply open in the original window so we need to start with a normal link.

<a href="http://www.w3.org">W3C</a>

Then we add some JavaScript that will open the new window and then supress the action of the link.

<a href="http://www.w3.org" onclick="window.open(this.href, 'child', 'height=400,width=300,scrollbars'); return false">W3C</a>

One of the big problems with the internet is that anybody can publish any thing and you cannot trust what you read. See http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/window.html#1202731 for details. You will note that using "config=" with the parameters is an error.