PDA

View Full Version : Script problem in NN



Haris
Jun 29th, 2002, 07:12 AM
Hi there,
I am facing some cross browser problems with my Javascript.The following scripts works well with IE but not with Netscape. I am using NN 4.7

function resetImageSize(w,h){
document.images["imgMain"].width=w;
document.images["imgMain"].height=h;
}


Why it is not changing the size in NN? I tried alert(document.images["imgMain"]) which returns [object/image].
When i try alert(document.images["imgMain"].width) or alert(document.images["imgMain"].height) it returns the sizes i have specified in the image tag in HTML, not the new one. Please help....

Thanks,
Haris.

brothercake
Jun 29th, 2002, 01:53 PM
In nn4 the width and height of an image are readonly properties, but resizing is possible if you rewrite a containing layer. So for example

<ilayer id="imgLayer"><img src="picture.gif" width=100 height=100 alt="" border=0></ilayer>


then you could change the dimensions like this


var iml = document.layers["imgLayer"];

iml.document.open();
iml.document.write('<img src="picture.gif" width=200 height=200 alt="" border=0>');
iml.document.close();

adios
Jun 29th, 2002, 06:37 PM
Can't .write() to an <ilayer> so you'll need to use a <layer>, possibly 'wrapped' to position it:

<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="JavaScript">

function resetImageSize(img_name, new_width, new_height) {
if (typeof document.layers == 'undefined') {
document.images[img_name].width = new_width;
document.images[img_name].height = new_height;
} else {
var parent = document['NS_' + img_name];
var old_width = parent.layers[0].document[img_name].width;
var HTML = '<img border="1" width="' + new_width + '" height="' + new_height + '" ';
HTML += 'src="' + parent.layers[0].document[img_name].src + '">';
parent.document.layers[0].document.write(HTML);
parent.document.layers[0].document.close();
parent.clip.width = parent.document.layers[0].clip.width;
parent.clip.height = parent.document.layers[0].clip.height;
parent.left -= (new_width - old_width)/2;
}
}

</script>
</head>
<body>
<a href="javascript&#58;void resetImageSize('imgMain', 316, 250)">reset</a>
<div align="center">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><ilayer id="NS_imgMain"><layer>
<img name="imgMain" border="1"
src="http://www.gwbush.com/images/bushcolinsomebadyfarted.jpg">
</layer></ilayer></td>
</tr>
</table>
</div>
</body>
</html>

Of course, might not be worth the trouble...