PDA

View Full Version : make this work in NS...


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

kdjoergensen
01-12-2001, 11:13 AM
netscape may not like that you use an image object as the url property of the window.open() method. Try changing to imgName or just leave blank (you are writing to the document anyway).

remember to close stream:
popup.document.close()

(netscape has in past had problems with multiple document.write statements. Try combine the statements into one text variable and make only one document.write statement).

onPageLoad is not a valid event handler in netscape. change the body tag's event handler to onload.

question:
Why do you put an absolutely positioned DIV element into the document ? would it not be enough to simply write
popup.document.open();
popup.document.write('<html><body>');
popup.document.write('<img src="+imageName+">');
popup.document.write('</body></html>');
popup.document.close();

?

Syst3m Err0r
01-12-2001, 01:13 PM
Yes I'm aware of the onPageLoad handler and I use the DIV tag because I want the picture at the absolute 0,0 point and then it crops the page to the dimentions of the picture.

I tried those tips you gave me but it didn't work.

The idea is that you only have to call the showFlyer function with out conserning about the properties of that pict/page.

call the function with the url of the picture and the rest is done by the script.

Greetz,

Syst3m Err0r