Javascript 如何从窗口外调用函数

Javascript 如何从窗口外调用函数,javascript,jquery,html,Javascript,Jquery,Html,如何调用在父窗口上声明的函数? 我有一个通过调用window.open打开的新窗口,新窗口的内容是一个网格,网格中的每个项目都有链接/锚定。在我的onclick事件中,我希望每个项都调用在父html上声明的函数。我怎样才能做到这一点? 下面是我的示例代码 function showCustomWindow(filter){ var title = ''; source = behindDueDates; title = 'Client Actions

如何调用在父窗口上声明的函数? 我有一个通过调用window.open打开的新窗口,新窗口的内容是一个网格,网格中的每个项目都有链接/锚定。在我的onclick事件中,我希望每个项都调用在父html上声明的函数。我怎样才能做到这一点? 下面是我的示例代码

function showCustomWindow(filter){

    var title = '';
         source = behindDueDates;
         title = 'Client Actions Behind Due Dates';

    var htmlContent = '<div id="content"><h2> '+ title +'</h2><table class="table" id="behindActions">';
        htmlContent +='<thead class="thead-inverse">';
        htmlContent += '<tr class="tableHeader">';
        htmlContent += '<td> Subject </td>';
        htmlContent += '<td> Regarding </td>';
        htmlContent += '</tr>';
        htmlContent += '</thead>';
        htmlContent += '<tbody>';

        $.each(source, function(key, value){
                var regarding = value.attributes.regardingobjectid;

                htmlContent += '<tr>';
                htmlContent += '<td data-id="'+value.Id+'"><a href="#" onclick="redirectToRecord("'+value.Id + "entity"+ value.attributes.activitytypecode.formattedValue +'")">' + value.getValue("subject") + '</a></td>';
                htmlContent += '<td>' + regarding + '</td>';
                htmlContent += '</tr>';
        })                

        htmlContent += '</tbody>';
        htmlContent += '</table></div>';

    var win = window.open("", title, "location=1,status=1,scrollbars=1,width=1000,height=800");
        win.moveTo(10, 10);
        win.document.write('<html><head><title> ' + title + ' </title></head><body>');
        win.document.write(htmlContent);
        win.document.write('</body></html>');

}
function redirectToRecord(value){
   alert("Event to call from second window")
}
函数showCustomWindow(过滤器){
var title='';
来源=过期日期;
标题=‘逾期客户行为’;
var htmlContent=''+title+'';
htmlContent+='';
htmlContent+='';
htmlContent+=‘主题’;
htmlContent+=“关于”;
htmlContent+='';
htmlContent+='';
htmlContent+='';
$.each(源、函数(键、值){
var about=value.attributes.regardingobjectid;
htmlContent+='';
htmlContent+='';
htmlContent+=''+关于+'';
htmlContent+='';
})                
htmlContent+='';
htmlContent+='';
var win=window.open(“,标题,“位置=1,状态=1,滚动条=1,宽度=1000,高度=800”);
赢。移动到(10,10);
赢。文件。写(“”+标题+“”);
win.document.write(htmlContent);
win.document.write(“”);
}
函数重定向记录(值){
警报(“从第二个窗口调用的事件”)
}

非常感谢您的帮助。

家长应参考打开的窗口


parent.method()
将调用一个方法。但它必须位于同一个域上,没有跨域调用将起作用。

使用windiw.opener helper调用父窗口函数:

if (window.opener != null && !window.opener.closed) {
    window.opener.function_in_parent(); //Parent window function
}

您可以通过以下方式访问子窗口:

var w = window.open("/uri", "title");
w.childFunction();
和家长:

<a onclick="parent.anyname();" href="#" > Click me </a>


或者尝试这种方法:

您阅读了吗?已经可以使用了,我的解决方法是在新窗口中添加一个EventListener。e、 g win.addEventLister('click',函数(值){redirectToRecord(值)},true)