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).
Code:
<!--
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;
_img.src=url_img;
// 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?