PDA

View Full Version : sorry guys(another new window size q)


matrix07
11-15-2002, 11:11 PM
hey guys, I have this script for a new window which will open an image with its dimensions. It works fine for one of my page where the images' dimensions are limited. But I want to use this same function for another page where the dimensions will vary.

I'd tried this. but object not found. Help please!

<a href="javascript:void(0);" onClick="openPic('someurl',document.images(this).width,document.images(this).height)"><img src="someimage.jpg"></a>



<script language=javascript type="text/javascript">
function openPic(url,width,height){
newWindow=window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,res izable=0');
newWindow.document.write('<html><title><\/title><head><\/head><body topmargin="0" leftmargin="0"><img src="'+url+'"><\/body><\/html>')
newWindow.resizeTo(width,height);
newWindow.focus();
}
</script>

kdjoergensen
11-16-2002, 01:43 PM
this inside the link refers to the LINK object and NOT the image object.

You can two options:

<img src="someimg.jpg" onClick="openPic(this.src,this.width,this.height)">

(which wont work in NS4, but should work in other browsers)

or:

<a href="javascript:void(0);" onClick="openPic(document.images['imgName'].src,document.images['imgName'].width,document.images['imgName'].height)"><img src="someimage.jpg" name='imgName'></a>

to cut down on the number of times you have to repeat the 'imgName', you could also do this:

<a href="javascript:void(0);" onClick="var useImage = 'imgName'; openPic(document.images[useImage].src,document.images[useImage].width,document.images[useImage].height)"><img src="someimage.jpg" name='imgName'></a>

This way the only thing you have to change every time is the first part of the onClick eventhandler: var useImage = 'nameOfNewImage'

matrix07
11-16-2002, 02:13 PM
hi there, thanks for your reply. I will try to use this code here since it's close to what I have already. Hmmm...but will this work on a thumbnail and then open up in original image? Sorry I should have mentioned that.
Cuz right now, aren't we just referencing my thumbnail pic if we did it this way? like say pic_tn.jpg is the thumbnail, and pic.jpg is the original.



<a href="java script:void(0);" onClick="openPic(document.images['imgName'].src,document.images['imgName'].width,document.images['imgName'].height)"><img src="someimage.jpg" name='imgName'></a>

kdjoergensen
11-16-2002, 06:37 PM
No, it will not work that way because it is reading the dimensions of the thumb nail

You could try:

<a href="java script:void(0);" onClick="openPic('/images/someLargeImage.gif',125,250)"><img src="someimage_tn.jpg" name='imgName'></a>

matrix07
11-17-2002, 02:52 PM
but then right now you're giving it a fixed height and width. The big pic will always be different so I just want to dymnatically get it's dimensions.

matrix07
11-18-2002, 06:07 PM
alright I got this working but I don't think this is an effecient way. For this particular script, it only works for one thumbnail, would like to make it so it works for multiple thumbnails. But anyway, any suggestions for making this script better?


<td colspan=2><a href="JavaScript:void(0);" onClick="openPic('images/girl.jpg');" border=0>
<img src="images/girl_tn.jpg" width=85 height=55 border=0></a></td>


<script language=javascript>
function openPic(url){
newWindow=window.open(url,'','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,res izable=0');
newWindow.document.write('<html><title></title><head></head>')
newWindow.document.write('<body onLoad="self.resizeTo(document.images[0].width,document.images[0].height);" topmargin="0" leftmargin="0"><img src="'+url+'"></body></html>')
newWindow.location.reload();
newWindow.focus();
}
</script>