javascript window.open打開新窗口后無法再次打開該窗口問題的解決方法
更新時間:2014年04月12日 11:05:39 作者:
這篇文章主要介紹了javascript window.open打開新窗口后無法再次打開該窗口問題的解決方法即無法再次打開窗口、第二次打開不了,需要的朋友可以參考下
在系統(tǒng)中,會一些地方使用javascript open window。比如打開固定模式的窗口,防止用戶進行其他操作。
參數:
復制代碼 代碼如下:
參數 | 取值范圍 | 說明
alwaysLowered | yes/no | 指定窗口隱藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口懸浮在所有窗口之上
depended | yes/no | 是否和父窗口同時關閉
directories | yes/no | Nav2和3的目錄欄是否可見
height | pixel value | 窗口高度
hotkeys | yes/no | 在沒菜單欄的窗口中設安全退出熱鍵
innerHeight | pixel value | 窗口中文檔的像素高度
innerWidth | pixel value | 窗口中文檔的像素寬度
location | yes/no | 位置欄是否可見
menubar | yes/no | 菜單欄是否可見
outerHeight | pixel value | 設定窗口(包括裝飾邊框)的像素高度
outerWidth | pixel value | 設定窗口(包括裝飾邊框)的像素寬度
resizable | yes/no | 窗口大小是否可調整
screenX | pixel value | 窗口距屏幕左邊界的像素長度
screenY | pixel value | 窗口距屏幕上邊界的像素長度
scrollbars | yes/no | 窗口是否可有滾動欄
titlebar | yes/no | 窗口題目欄是否可見
toolbar | yes/no | 窗口工具欄是否可見
Width | pixel value | 窗口的像素寬度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
實例:
復制代碼 代碼如下:
window.open("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no,resizable=no, location=no, status=no")
根據分辨率計算高度和寬度后打開:
復制代碼 代碼如下:
var ht = screen.height-98;
var widhh = screen.width - 20;
window.opener = null;
window.open("", "_self");
window.open("Main.aspx", "newwindow" + JsGuid(),
"height=" + ht + ", width=" + widhh + ",
depended=yes,top=0,left=0,toolbar=no, menubar=no,
scrollbars=yes, resizable=no, location=no, status=yes");
window.close();
var widhh = screen.width - 20;
window.opener = null;
window.open("", "_self");
window.open("Main.aspx", "newwindow" + JsGuid(),
"height=" + ht + ", width=" + widhh + ",
depended=yes,top=0,left=0,toolbar=no, menubar=no,
scrollbars=yes, resizable=no, location=no, status=yes");
window.close();
并關閉原來的窗口。
問題:
在window.open后,如果系統(tǒng)退出,再次使用window.open打開新頁面的時候,會出現錯誤。
google了半天也沒找到。一想這個問題應該不常發(fā)生肯定是配置的問題。
其中,我們可以看到window.open的第二個參數是新窗口的名字。這個名字是不能重復的。
如果重復了就是一直在這個窗口打開刷新。
所以我加了一個js的隨機GUID函數。
復制代碼 代碼如下:
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
function JsGuid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
};
function JsGuid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
打開窗口的時候使用:window.open("Main.aspx", "newwindow" + JsGuid());
OK,問題解決。
相關文章
setinterval()與clearInterval()JS函數的調用方法
這篇文章主要介紹了setinterval()與clearInterval()JS函數的調用方法,實例分析了setinterval()與clearInterval()的語法結構及使用技巧,需要的朋友可以參考下2015-01-01