Forum Moderators: open
function newWindow(img,title,w,h) {
// Creates a relatively UNIQUE window id so that subsequent
// links don't load in the same window
var day =new Date();
var id = day.getTime();
var wt = w+50; // make room for scrollbars
var ht = h+125; // scrollbars and close button
//Personally, I think developers who ignore the screen height and allow
// the window to go off the bottom of the screen should have their feet cut off,
// just like their windows on smaller monitors.
if ((screen.height) && (ht > screen.height-150)) {
ht = screen.height-150;
}
var params = 'width='+wd+',height='+ht'+',scrollbars';
// TWO OPTIONS HERE: open a new window and doc. write or load a URL
// OPTION 1
var win = open('',id,params);
win.document.write('<html><head><title>'+title+</head><body><div align="center">+<h3>'+title+'</h3>\n');
win.document.write('<img src="images/'+img+'" width="'+w+'" height="'+h+'" border="0" alt="'+title+'"><br>\n');
win.document.write('<form><input type="button" onClick="window.close();" value="Close Window"><br></body></html>');
//A common mistake for newbies: closing the doc flushes the buffer.
// Not closing it prints blank window
win.document.close();
// OPTION 2: this requires only passing w and h
// (window width and height) and loads an actual
// HTML file instead of an image for img.
// var win = open(img,id,params);
} // Dass all
To call it with method 1:
<a href="javascript:newWindow('large_img.jpg','My Image',300,250);"><img src="images/thumbnail.jpg" width="75" height="50" border="0" alt="Small Image"></a>
Method 2, linked to an HTML page, just sub html for image and leave title blank:
<a href="javascript:newWindow('large_image.html','',300,250);"><img src="images/thumbnail.jpg" width="75" height="50" border="0" alt="Small Image"></a>
The previous has not been debugged and may contain errors, but I use it all the time without trouble. So far. :-)