Forum Moderators: open

Message Too Old, No Replies

popup window problems

invalid argument that had been working earlier

         

mcvoid

5:36 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



I'm trying to make a small function that allows me to open an image in a pop-up window and have the window sized to the image, but it isn't working, even though i had an earlier version working just fine. The error message states an invalid argument at the line with the window.open() method.

The function looks like this :
<script LANGUAGE="JavaScript">
<!--
function popImage(filename)
{
aWindow=window.open(filename,'Picture Viewer','status=no,menubar=no,scrollbars=no,toolbar=no,resizable=no,dependent=yes,modal=yes,dialog=yes');

aWindow.resizeTo(aWindow.document.images[0].width,aWindow.document.images[0].height);
}
// -->
</script>

An instance where I use it is here:
<a href="javascript: popImage('images/jul01army1.jpg');">

I also tried an onClick statement that looked like this:
<img src="images/jul01army1a.jpg" border="0"width="90" height="67" onClick="popImage('images/jul01army1.jpg');">

Neither of them work now, but it was just working the other day before i cleaned up the code a bit. What did i do wrong?

Dijkgraaf

7:23 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It works with FireFox, but not with IE.

The issue is the name you are giving the new window, it can't have a space in it with IE.
So change 'Picture Viewer' to 'PictureViewer'

mcvoid

7:47 pm on Mar 30, 2006 (gmt 0)

10+ Year Member



It works! I figured it was some minor stupid thing. (Isn't it always?) Thank you so much.

As a related point, I was browsing the older topics and I noticed that there are quite a few exceptions to details of Jscript that don't fit in with other browers' versions of JavaScript. Is it just that Jscript doesn't completely conform to the standard?

Dijkgraaf

7:51 pm on Mar 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you mean standards in IE versus other browser?
Microsoft has a tendency to try and set the standards themselves, much to the annoyance of many. Occasionaly they get sucesfully sued about it, like Sun did when Microsoft decided to add things to Java (not JavaScript) that were outside the standards and the agreement they had with Sun.
At other times they have added something new before there was a standard for it.
It is still a rapidly evolving technology, so I'd expect it will be a while before the dust settles :-)

mcvoid

3:10 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



OK, for round 2.
I noticed that while keeping the window open and clicking on a second pic, the window (and image) get steadily smaller with each execution of this code. It's probably due to IE's automatic image resizing to fit the window in the first place.
There's several ways to work around this, but I decided with my limited JS experience to go with the following code:

function popImage(filename)
{
aWindow=window.open(filename,'PictureViewer','status=no,menubar=no,scrollbars=no,toolbar=no,resizable=no,dependent=yes,modal=yes,dialog=yes,');
ht = 0;
wd = 0;
if(aWindow.height!= awindow.document.images[0].height ¦¦ aWindow.width!= awindow.document.images[0].width)
{
if (aWindow.height!= awindow.document.images[0].height) ht = aWindow.document.images[0].height - aWindow.document.images[0].height;
if (aWindow.width!= awindow.document.images[0].width) wd = aWindow.document.images[0].width - aWindow.document.images[0].width;
aWindow.resizeBy(wd,ht);
}
}

This works, as in the picture never gets any smaller, but now there's a lot more white space around each image and it doesn't resize as neatly to the image. I realize that (like Perl's motto) there's more than one way to do it, so I was wondering if anyone had some improvements or alternative suggestions.