1

I am working with IE9. Want to open a popup window from a page, and from the popup, how to call the javascript code in the page (not the popup window)?

There will not be a cross domain issue as I am going to load a page from the same domain of the page into the popup window.

4

2 回答 2

3

就像 Cory 说的,window.opener用来获取父窗口的window. 看这个:

http://jsfiddle.net/Dmnqk/

function openPopup() {
    var w = window.open("", "");
    w.document.open();
    w.document.write("<script type='text/javascript'>window.opener.parentWindowFunction();<\/script>");
    w.document.close();
}

function parentWindowFunction() {
    alert("called");
}

当然,我的使用document.open/write/close只是创建我自己的页面来调用父窗口的函数(从技术上讲,它应该真的有<html><head></head><body>SCRIPT HERE</body></html>。你的弹出页面需要的只是调用window.opener.parentWindowFunction.

于 2012-12-12T00:00:39.523 回答
0

您可以使用window.opener来访问window打开弹出窗口的页面的全局 ( ) 命名空间中的函数:

开瓶器

function functionFromOpener() {
    return "wharrgarbl";
}

弹出

alert(window.opener.functionFromOpener());

强制性 jsFiddle 示例:http: //jsfiddle.net/9yLu2/1/

也就是说,我认为使用页内 DHTML 对话框是一个更好的主意。(或者可能是浏览器窗口无法调整大小/没有地址栏让我很烦。)

于 2012-12-12T00:03:09.163 回答