2017-02-22 45 views
0

我有一個使用Javascript打開彈出文件選擇器窗口的頁面。用戶選擇文件後,父窗口將重定向到加載文檔的頁面。我已經準備好了很多有同樣問題的帖子,但還沒有找到解決方案。我有以下代碼:Javascript - 將父頁重定向到彈出的新頁面

家長

openChildWindow("FileMan2.aspx?UN=<%= Header1.UserNumber %>&FormMode=OPEN&RetObj=PRINTLETTER&PrintCase=" + OpenFlag, 550, 350); 

function openChildWindow(URL, width, height) { 
     if (window.showModalDialog) { 
      window.showModalDialog(URL, window.self, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:yes;scroll:no;resizable:no;status:no;unadorned:no;edge:raised"); 
     } else { 
      window.open(URL, "docman", "width=" + width + ", height=" + height + ", screenX=0, screenY=0, status=no, scrollbars=no,toolbar=no,menubar=no,top=200,left=200,modal=yes"); 
     } 
    } 

兒童

var URL = window.location.protocol + "//" + window.location.host + "/CaseLetter.aspx?Case=<%= CaseNumber %>&UN=<%= Header1.UserNumber %>&Letter=" + file + "&FileName=" + file + "&COID=<%=GlobalVar.LawFirm %>&FilePath=<%= AddPath %>"; 
     window.opener.location.href = URL; 

URL計算結果爲 「http://example.com:80/CaseLetter.aspx?Case=35251&UN=1&Letter=asdf&FileName=asdf&COID=ar000001&FilePath=

我得到的錯誤是「無法獲得財產「的位置'未定義或空引用。我在這裏做錯了什麼?

+0

'window.opener'不'window.showModalDialog' https://forums.asp.net/t/1123330.aspx?using+window+opener+with工作+在showModalDialog – chiliNUT

回答

0

我會選擇將變量的引用存儲到變量中,然後使用其closed布爾屬性來查看模式何時關閉,如下所示(這在運行下面的代碼片段時不起作用,因爲stackoverflow會阻止模式,但您可以通過將其複製到您的chrome開發工具控制檯進行驗證)。

let modal = window.open("https://www.google.com?q=cats", "docman", "width=500,height=500,screenX=0, screenY=0,status=no,scrollbars=no,toolbar=no,menubar=no,top=200,left=200,modal=yes") 
 

 
function onClose() { 
 
    alert("Modal was closed") 
 
} 
 

 
let intervalID = setInterval(() => { 
 
    if(modal && modal.closed) { 
 
    clearTimeout(intervalID) 
 
    onClose() 
 
    } 
 
}, 200)