简体   繁体   English

Javascript-从弹出窗口将父级重定向到新页面

[英]Javascript - Redirect parent to new page from popup

I've got a page that opens a popup file picker window using Javascript. 我有一个页面,可以使用Javascript打开弹出文件选择器窗口。 Once the user selects a file the parent window redirects to a page that loads the document. 用户选择文件后,父窗口将重定向到加载文档的页面。 I've ready many posts with the same problem, but haven't found the solution. 我已经准备了很多有相同问题的帖子,但是还没有找到解决方案。 I have the following code: 我有以下代码:

Parent

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");
        }
    }

Child 儿童

 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 evaluates to " http://example.com:80/CaseLetter.aspx?Case=35251&UN=1&Letter=asdf&FileName=asdf&COID=ar000001&FilePath= " 网址评估为“ http://example.com:80/CaseLetter.aspx?Case=35251&UN=1&Letter=asdf&FileName=asdf&COID=ar000001&FilePath=

The error I'm getting is "Unable to get property 'location'of undefined or null reference. What am I doing wrong here? 我收到的错误是“无法获取未定义或空引用的属性'位置'。我在这里做错什么?

I would go the route of storing the reference to the modal in a variable, then poll to see when the modal is closed using its closed boolean property like so (this will not work when running the snippet below because stackoverflow blocks modals but you can verify by copying it into your chrome dev tools console). 我会选择将对模态的引用存储在变量中的路线,然后轮询以使用模态的closed布尔值属性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) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM