Syst3m Err0r
01-12-2001, 08:04 AM
I've written a JavaScript function that opens a picture in a new window with the exact dimentions of the picture.
the only thing you'll have to do is call the function like this:
<a href="javascript:showFlyer('...url of the picture')">click here</a>
The only thing is that it doesn't work in NS and my question is. To make it NS compatible and if possible the code even smaller.
here's the script so far:
<script language="JavaScript">
<!--//
function showFlyer(imgName) {
var image = new Image();
image.src = imgName;
popup = window.open( image ,'_blank','Height="0",Width="0",scrollbars=no,resize=no,left=0,top=0');
popup.document.write('<html><head><title>');
popup.document.write(imgName);
popup.document.write('</title><script language="JavaScript">');
popup.document.write('function fitWindowSize() {');
popup.document.write('width = 10+ (document.images[0].width);');
popup.document.write('height = 28 + (document.images[0].height);');
popup.document.write('window.resizeTo(width, height);}');
popup.document.write('</script></head>');
popup.document.write('<BODY onPageLoad="fitWindowSize();">');
popup.document.write('<div style="position:absolute; left:0px; top:0px">');
popup.document.write('<img src=" ' + imgName + '" onLoad="fitWindowSize();">');
popup.document.write('<script>fitWindowSize();setTimeout(fitWindowSize(),200);</script>');
popup.document.write('</div>');
popup.document.write('</body></html>');
}
//-->
</script>
greetz,
Syst3m Err0r
the only thing you'll have to do is call the function like this:
<a href="javascript:showFlyer('...url of the picture')">click here</a>
The only thing is that it doesn't work in NS and my question is. To make it NS compatible and if possible the code even smaller.
here's the script so far:
<script language="JavaScript">
<!--//
function showFlyer(imgName) {
var image = new Image();
image.src = imgName;
popup = window.open( image ,'_blank','Height="0",Width="0",scrollbars=no,resize=no,left=0,top=0');
popup.document.write('<html><head><title>');
popup.document.write(imgName);
popup.document.write('</title><script language="JavaScript">');
popup.document.write('function fitWindowSize() {');
popup.document.write('width = 10+ (document.images[0].width);');
popup.document.write('height = 28 + (document.images[0].height);');
popup.document.write('window.resizeTo(width, height);}');
popup.document.write('</script></head>');
popup.document.write('<BODY onPageLoad="fitWindowSize();">');
popup.document.write('<div style="position:absolute; left:0px; top:0px">');
popup.document.write('<img src=" ' + imgName + '" onLoad="fitWindowSize();">');
popup.document.write('<script>fitWindowSize();setTimeout(fitWindowSize(),200);</script>');
popup.document.write('</div>');
popup.document.write('</body></html>');
}
//-->
</script>
greetz,
Syst3m Err0r