View Full Version : Picture dimensions centered

10-20-2003, 07:28 PM
This *.js file creates a centered popup based upon the dimensions (width, height) of the picture that is referred to.
A click on the picture will close the window (aswell).

function show_image(url_img,popup_title,img_alt){
// pop-up configuration
var _resizable=0;
var _status=0;
var _scrollbars=0;

//load image
var _img = new Image;

// get/calculate required variables
var _w=_img.width;
var _h=_img.height;
var winl = (screen.width - _w) / 2;
var wint = (screen.height - _h) / 2;

// open window
var _win=window.open("","","height="+(_h)+", width="+_w+", top ="+wint+", left = "+winl+", resizable="+_resizable+", status="+_status+", scrollbars="+_scrollbars);

// write html content in new window
_win.document.write("<html>\n <head>\n <title>\n\t"+popup_title+"\n</title>\n</head>\n");
_win.document.write("<body style=\"margin:0px;\">\n");
_win.document.write("<img src=\""+url_img+"\"\n\t alt=\""+img_alt+"\" onClick=\"window.close();\">\n");
_win.document.write(" </body>\n</html>");

(see the attached Zip file for an example)

The strange thing is that only the very first time the window is called / 'made' it is NOT centered, but at the bottom right corner and NOT in the specified dimensions. Every next time it works just great, even after deleting the cache. Beats me. My single guess is that perhaps a built in delay will do the trick properly / the first time aswell???

My problem is, if that's the solution, how / where to built in a time-delay? Any help / suggestions are appreciated.

Ps IE 5 and 6, XP and windows 95 tested. 2nd question: Is this an IE-thing only?

10-21-2003, 12:11 AM
LOL :) It seems like I'm having this one solved by adding one single line:

_win.document.write("<meta http-equiv=\"refresh\" content=\"0; URL=url_img\" >\n");

Don't know / understand why but it works...

Thanks for 'all' the help ;) :) and in the hope the script benefits others...

Greetings, Jan.

10-21-2003, 04:32 PM
Sorry. Got a bit overexcited it seems... Problem still excists. :(

Would somebody please, please be so kind to help me solve it?

I noticed a script by 'Beetle' which looked quite simular. I could not get the popups centered in that script either. If possible I prefer solving the problem in this script (if Beetle don't mind, that is. ;) LOL)

Roy Sinclair
10-21-2003, 04:48 PM
I downloaded your example and it works every time, it never put the popup anywhere except centered like it's supposed to no matter how many times I closed and re-opened the browser.

(Tested with IE6 SP1 on W2K)

10-21-2003, 05:01 PM
Well..., I'm not making it up. ;) Tested it on severall cliŽnts aswell... :rolleyes:

I've noticed, by changing the image (severall times), the problem does not occure on every single one of them.

Perhaps if you change the image you'll encounter the same problem I'm having? (Remember: only at first / the very first time).

Thanks btway for responding ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum