This JavaScript opens a pop-up window with one of three sizes, depending on the user's screen resolution. This script should work with all "modern" browsers (Safari, Internet Explorer 5+, Netscape 6+, etc.) as well as Netscape 4, aka "The Bane of All Web Developers."
According to ARTIS Small Screen the "safe" sizes for the different resolutions are as follows:
| 640 x 480 | 800 x 600 | 1024 x 768 |
|---|---|---|
| 584 x 290 | 744 x 410 | 968 x 578 |
Your resolution appears to be unknown. Open the pop-up.
// speeds things up
d = document;
// screen widths
screenW = new Array("640","800","1024");
screenH = new Array("480","600","768");
// safe widths
safeW = new Array("584","744","968");
safeH = new Array("290","410","578");
function init()
{
// get resolution
wdth = screen.width;
hght = screen.height;
// use object detection to determine browser capabilities
(d.getElementById)?modern=true:modern=false;
(d.layers)?nn4=true:nn4=false;
// if netscape 4, show user an alert with the width and height
if (nn4) alert("Your resolution appears to be " + wdth + " x " + hght);
// if it's a modern browser, write resolution to span
if (modern) d.getElementById("res").innerHTML = wdth + " x " + hght;
}
function openIt(loc)
{
// get resolution again in case user has changed resolutions
wdth = screen.width;
hght = screen.height;
// find position in array for user's width
// (we'll use the corresponding height to keep the aspect ratio correct)
if (wdth <= 640) p = 0;
if (wdth == 800) p = 1;
if (wdth >= 1024) p = 2;
// make features string
ftrs = "width=" + safeW[p] + ",height=" + safeH[p] + ",scrollbars=auto,resize=yes";
// open the pop-up window
window.open(loc,'popup',ftrs);
}