Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    wiz
    wiz is offline
    New to the CF scene
    Join Date
    Aug 2004
    Location
    Liberal, KS
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get image properties in Safari for popup

    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,height=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();
    }

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Try this:
    Code:
    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,dependent,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();
    }

  • #4
    wiz
    wiz is offline
    New to the CF scene
    Join Date
    Aug 2004
    Location
    Liberal, KS
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •