Javascript window.open
使用window.open開啟新的視窗。以下是程式碼:
function openMenuUrl(url, windowId){
if(windowId){
windowId = windowId + cs2_generateTempId(windowId);
var scalar = 0.9;
var w_ht = Math.round(scalar * screen_ht);
var w_wd = Math.round(scalar * screen_wd);
var w_left = Math.round((screen_wd-w_wd)*0.5);
var w_top = Math.round((screen_ht-w_ht)*0.5);
windowparms = "resizable=yes,status=yes,scrollbars=yes,";
windowparms += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
windowparms += "height=" + w_ht + ",width=" + w_wd + ",toolbar=no";
if (isStandardZoneFunction(url)){
window.open("../transition.htm", windowId, windowparms);
} else if(url.indexOf("cs1MocToMcc=true") == -1){
window.open("../progress.htm", windowId, windowparms);
}
if((myNewWin = window.open(url, windowId, windowparms)) == null ) {
var_proceed=true;
return;
}
myNewWin.focus();
var_proceed=true;
} else{
window.location.href = url;
}
}
期望行為是能在新視窗當中先看到transition.htm的內容,然後再跳轉到傳入的url。
但是FF/Chrome中,不能看到transition.htm的內容。
原因:
https://developer.mozilla.org/en-US/docs/DOM/window.open
The open() method creates a new secondary browser window, similar to choosing New Window from the File menu. The strUrl parameter specifies the URL to be fetched and loaded in the new window. If strUrl is an empty string, then a new blank, empty window (URL about:blank) is created with the default toolbars of the main window.
Note that remote URLs won't load immediately. When window.open() returns, the window always contains about:blank. The actual fetching of the URL is deferred and starts after the current script. block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.
解決方法:
function openMenuUrl(url, windowId){
if(windowId){
windowId = windowId + cs2_generateTempId(windowId);
var scalar = 0.9;
var w_ht = Math.round(scalar * screen_ht);
var w_wd = Math.round(scalar * screen_wd);
var w_left = Math.round((screen_wd-w_wd)*0.5);
var w_top = Math.round((screen_ht-w_ht)*0.5);
windowparms = "resizable=yes,status=yes,scrollbars=yes,";
windowparms += "left=" + w_left + ",top=" + w_top + ",screenX=" + w_left + ",screenY=" + w_top + ",";
windowparms += "height=" + w_ht + ",width=" + w_wd + ",toolbar=no";
if (isStandardZoneFunction(url)){
window.open("../transition.htm", windowId, windowparms);
} else if(url.indexOf("cs1MocToMcc=true") == -1){
window.open("../progress.htm", windowId, windowparms);
}
setTimeout(function() {
if((myNewWin=window.open(url,windowId,windowparms))==null) {
return;
}
myNewWin.focus();
}, 1000);
var_proceed=true;
} else{
window.location.href = url;
}
}
此處用到了setTimeout與閉包。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8520577/viewspace-754948/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- JavaScript檢測window.open()彈出視窗是否被攔截JavaScript
- window.open 詳解
- window.open()總結
- window.open()開啟新視窗教程
- window.open()和target= blank存在安全漏洞
- window.open()函式引數用法詳解函式
- 記一次小坑–關於window.open()
- 記一次小坑--關於window.open()
- safari 回撥中window.open無法執行
- 如何防止window.open彈窗被瀏覽器遮蔽瀏覽器
- JS中window.open和window.opener的使用薦JS
- 如何防止window.open()開啟網頁快取問題網頁快取
- 防止window.open()函式彈出視窗被攔截函式
- 怎樣讓window.open('aa.jsp')共享資料JS
- js檢測window.open()彈出視窗是否被關閉JS
- 請教JAVA前輩:在javascript中window.open("index.jsp","_parent")中,_parent引數是什麼意思?JavaScriptIndexJS
- 解決ajax回撥window.open瀏覽器阻止彈窗問題瀏覽器
- window.open()實現彈出視窗居中顯示程式碼例項
- IE8下window.open 二次無法載入頁面
- 使用window.open()函式開啟一個新頁面程式碼例項函式
- ajax回撥中使用window.open彈窗被chrome攔截的問題Chrome
- handle中存在非同步操作,window.open被瀏覽器阻止的問題非同步瀏覽器
- js實現window.open()彈出視窗和父視窗之間相互操作JS
- 使用window.open開啟新視窗被瀏覽器攔截的解決方案瀏覽器
- 移動端window.open跳轉連結時,iOS沒有反應的問題iOS
- js window.open()實現列印,如何在關閉列印視窗時重新整理父視窗JS
- JavaScript高階:JavaScript物件導向,JavaScript內建物件,JavaScript BOM,JavaScript封裝JavaScript物件封裝
- javaScript系列[06]-javaScript和thisJavaScript
- safair瀏覽器 在回撥中跳轉 window.open 打不開頁面 但是有判斷,跳轉不了AI瀏覽器
- 【JavaScript學習】JavaScript物件建立JavaScript物件
- 【轉】eval()函式(javascript) - [javaScript]函式JavaScript
- [Javascript] How javascript read the property?JavaScript
- JavaScript -"this"JavaScript
- javascript ??JavaScript
- This in JavaScriptJavaScript
- “This” is For JavaScriptJavaScript
- javascript thisJavaScript
- JavaScriptJavaScript