請看下列腳本:<script language="javascript">function aa(){var aa=open(" m","aa","scrollbars=1,resizable=1,width=568,height=490,top=20,left=102");}</script>以上表示的新窗口在800×600屏幕中絕對左右居中。但在1024×768屏幕中此窗口就偏到左上方了。如何編寫腳本,使同一窗口無論在800×600、或1024×768、或其他分辨率的屏幕中都能出現在絕對左右居中的位置?(我指的是已設定大小的窗口,例如以上width=568,height=490這一設定不變。)

熱心網友

下面框中為腳本顯示區function openwindow( url, winName, width, height) {xposition=0; yposition=0;if ((parseInt(navigator。appVersion) = 4 )){xposition = (screen。width - width) / 2;yposition = (screen。height - height) / 2;}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 );}//--打開窗口。

熱心網友

有一個默認對象screen,你可以取到顯示的分辨率,比如800×600,那么screen.width=800;screen.height=600.你可以通過計算確定新窗口的左頂點位置,也即上面的top、left值。比如:left=(screen.width-568)/2