<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>标题页</title> <script language="javascript"> //参数-url表示要打开的网站,winname表示打开后的窗体名称 //参数windth表示打开窗体的宽度,height表示打开窗体的高度 <!-- function openwindow( url,winName,width,height) { xposition=0; yposition=0; if ((parseInt(navigator.appVersion) >= 4 )) { xposition = (screen.width - width) / 2; //窗体居中的x坐标 yposition = (screen.height - height) / 2; //窗体居中的y坐标 } theproperty= "width=" + width + "," //打开窗口的属性 + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=0," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," //仅适用于Netscape + "screeny=" + yposition + "," //仅适用于Netscape + "left=" + xposition + "," //IE + "top=" + yposition; //IE window.open( url,winName,theproperty ); //打开窗口 }//--> </script> </head> <body> <a href="javascript:openwindow('http://www.google.com','openwin',300,300)"> 打开窗口</a></body> </html>
本例的重点是设置打开窗口的一些属性。“window.open”方法用来打开窗口,此方法的三个参数分别代表:要打开窗口的URL、打开窗口的名字、打开窗口的一些属性(如是否有滚动条、最大化按钮等)。本例使用“(screen.width-width)/2”和“(screen.height-height)/2”获取窗体居中的坐标点,然后指定窗体的“left”和“top”属性。