親ウィンドウで宣言されている関数を呼び出すにはどうすればよいですか? 私は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")
}
ご協力いただきまして誠にありがとうございます。
あなたはhttp://www.tonybhimani.com/2011/10/16/javascript-controlling-a-popup-windows-parent-window/を読んでいますか? – thepiercingarrow
すでに動作していますが、私の回避策は新しいウィンドウにEventListenerを追加することです。例:win.addEventLister( 'click'、function(value){redirectToRecord(value)}、true) – user3197077