Jump to content

Open image in new window


Guest Aniqua
 Share

Recommended Posts

I'm trying to open an image in a new window, and I would like the window to adjust to the size of the image. My function looks like this: function openpic(imageID){$bild = "http://www.bricklink.com/SL/"+imageID+".jpg";window.open($bild, '_blank','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=500, height=350')} but I want the window to be the same size as the image and not resizable. Any suggestions?

Link to comment
Share on other sites

You're on the right track for opening a new window. I would only add the following:

var props = "toolbar=no,location=no,directories=no,status=no,menubar=no,";props	+= "scrollbars=no,resizable=no,copyhistory=no,width=50,height=50";var wnd = window.open('', 'myImage', props);

This way, you'll have a reference to the window object in the "wnd" variable.You'll need to use the HTML DOM for the rest of it. The next step would be to get at the document object for the new window so that you can write contents to the new window:

var doc = wnd.document;doc.open("text/html", "replace");doc.write("<html><body style='margin: 0px;'><img src='" + theImagePath + "' id='theImage' /></body></html>");doc.close();

Then you'll get at the image object in that document to see what size it is:

var img = doc.getElementById("theImage");var width = img.width;var height = img.height;

And finally, you can use the resizeTo method of the window object to resize your popup window:

wnd.resizeTo(width, height);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...