// ***** -------------- ***** // ***** makewin.js ***** // ***** -------------- ***** /* +----------------------------------------------------------------------+ | JavaScript Function | +----------------------------------------------------------------------+ | NAME: makewin | | | | AUTHOR: Chad Kuehn | | | | DESCRIPTION: | | Used to create a popup window and close it when the page unloads. | | Default properties: | | -resizable = true | | -width = "500" | | -height = "300" | | -scrollbars = true | | | | PARAMETERS: | | url - The url of the popup window. Does not handle custom | | messages. | | width - The width of the window. (default 500) | | height - The height of the window. (default 300) | | properties - Adjust othee window properties. (optional) | | Use an associative array to adjust these properties. | | resizable | | menubar | | toolbar | | status | | directories | | location | | scrollbars | | (e.g., {'menubar' : 1, 'resizable' : 0}) | | | | DETAILS: | | If the popup window is open, it will have the focus placed on it | | if the script is re-executed. | +----------------------------------------------------------------------+ | Copyright (c) chadkuehn.com | +----------------------------------------------------------------------+ */ var winxx; //global variable var winnamexx = 'win' + uniqid(); var persistxx = false; function makewin(url, width, height) { var winLeft; var winTop; if (winxx) { if(!winxx.closed) { winLeft = (winxx.screenLeft ? parseInt(winxx.screenLeft) : parseInt(winxx.screenX)); winTop = (winxx.screenTop ? parseInt(winxx.screenTop) : parseInt(winxx.screenY)); closewinxx() } } if((width == null) || (width == '')) { width = 500; } if((height == null) || (height == '')) { height = 300; } var altSettings = new Array(); if(arguments.length == 4) { altSettings = arguments[3]; } var xresizable = 1; var xmenubar = 0; var xtoolbar = 0; var xstatus = 0; var xdirectories = 0; var xlocation = 0; var xscrollbars = 1; for (var i in altSettings) { switch(i) { case "resizable": xresizable = altSettings[i]; break; case "menubar": xmenubar = altSettings[i]; break; case "toolbar": xtoolbar = altSettings[i]; break; case "status": xstatus = altSettings[i]; break; case "directories": xdirectories = altSettings[i]; break; case "location": xlocation = altSettings[i]; break; case "scrollbars": xscrollbars = altSettings[i]; break; } } var settings ='width = ' + width; settings += ', height = ' + height; settings += ', resizable = ' + xresizable; settings += ', menubar = ' + xmenubar; if(winLeft != null) { settings += ', left=' + winLeft + 'px'; } if(winTop != null) { settings += ', top=' + winTop + 'px'; } settings += ', toolbar = ' + xtoolbar; settings += ', status = ' + xstatus; settings += ', directories = ' + xdirectories; settings += ', location = ' + xlocation; settings += ', scrollbars = ' + xscrollbars; if((url.substr(0, 1) == '/') || (url.substr(0, 4) == 'http')) { winxx = window.open(url, winnamexx, settings); } else { winxx = window.open('', winnamexx, settings); winxx.document.write(url); } } function closewinxx() //some programs call this script function directly { if(winxx) { if(!winxx.closed) { if(persistxx == false) { winxx.close(); winxx = null; } persistxx = false; } } } addEvent(window, "unload", closewinxx); function addEvent(obj, eventName, func) { if(obj.addEventListener) { if(eventName.substr(0, 2) == 'on') { eventName = eventName.substr(2); } obj.addEventListener(eventName, func, false); return true; } else if (obj.attachEvent) { if(eventName.substr(0, 2) != 'on') { eventName = 'on' + eventName; } return obj.attachEvent(eventName, func); } else { return false; } } function uniqid() { var len; if(arguments.length == 0) { len = 13; } else { len = arguments[0]; } var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var i; var seq = ""; for (i = 1; i <= len; i = i + 1) { seq += randomChar(letters); } return seq; } function randomChar(str) { return str.charAt(randomInt(0, str.length-1)); } function randomInt(low, high) { return Math.floor(Math.random()*(high-low+1)) + low; }