...

View Full Version : Can't get image properties in Safari for popup



wiz
08-30-2004, 12:27 AM
The goal is to open a popup window that resizes itself to fit the natural size of an image without requiring the width and height in the parms. The following JS function works fine on Mac in Netscape 7.2 and MSIE 5, but fails in Safari 1.2.3 as noted. Been trying workarounds in Safari for a week. No luck. Anyone care to try? Does it work on Windows browsers? (note extraneous return & space in he ight in window.open line contributed by the posting process).


// Popup Image in new window
// works in Mac Netscape & IE but in Safari onblur doesn't work & it takes two clicks on the same thumbnail to get the window to resize properly, which it does with one click thereafter.

function winPopUp(source,theTitle) {

var win0 = window.open("",theTitle,"toolbar=no,dependent=yes,directories=no,menubar=no,scrollbars=no,resizable=no,dependent,width=640,he ight=640");

var d = win0.document;
if(!d.images[0]) { // first pass
d.write("<html><head><title>" + theTitle + "</title></head>");
d.write("<body onclick=self.close();onblur=self.close();>");
d.write("<img src=\"" + source + "\">");
d.write("</body></html>");
d.close();
}
var theImg=d.images[0];
theImg.src=source;

// trying to get width & height doesn't work on first pass in Safari (gets 0's) - apparently takes second pass on same image to update image properties.

var width=theImg.width + 25;
var height=theImg.height + 40;
win0.resizeTo(width,height);

win0.moveTo(100,150);
win0.focus();
win0.stop();
}

jamescover
08-30-2004, 03:53 AM
see if this one works in Safari:

http://www.theseafordmovingwall.com/gallery.php

if so, might give you some insight into why yours' won't...

-james

glenngv
08-30-2004, 05:07 AM
Try this:


function winPopUp(source, theTitle) {
var win0 = window.open("", theTitle, "left=100,top=150,toolbar=no,dependent=yes,directories=no,menubar=no,scrollbars=no,resizable=no,depen dent,width=640,height=640");
var d = win0.document;
d.write("<html><head><title>" + theTitle + "</title></head>");
d.write("<body onclick=self.close();onblur=self.close();>");
d.write('<img src="' + source + '" onload="window.resizeTo(this.width+25, this.height+40);">');
d.write("</body></html>");
d.close();
win0.focus();
}

wiz
08-30-2004, 06:32 AM
Thanks Jamescover & Glenngv for your rapid response. Glenngv's script does the trick for all three browsers. Very clever, I wouldn't have thought of it.

Any idea how to hide the loading and resizing gyrations until the final popup window is ready to view? I have tried off-screen top and left coordinates when opening, but didn't seem to work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum