Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center a New Window

Opening and closing a window

Center a New Window

by  jemminger  Posted    (Edited  )
[color #000099]
Code:
function newWindow(sURL, sName, w, h) {
	//  your new window's width
	var w = w || 640;
	//  your new window's height
	var h = h || 480;
	var sName = sName || ("win" + new Date().getTime());
	
	var ah = window.screen.availHeight;
	var aw = window.screen.availWidth;
	var l = (aw/2) - (w/2);
	var t = (ah/2) - (h/2);
	var sAtts = "location=yes" + 
		",menubar=yes" + 
		",resizable=yes" + 
		",scrollbars=yes" + 
		",status=yes" + 
		",toolbar=yes" +
		",height=" + h + 
		",width=" + w + 
		",top=" + t + 
		",left=" + l;		
		
	window.newWin = window.open(sURL, sName, sAtts);
}
[/color]

easy to use!

as a link:
<a href="#" onclick="newWindow('http://www.ebay.com/', 'ebay', 400, 300);">LINK</a>

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top