Как я могу вызвать функцию, объявленную в родительском окне? У меня есть новое окно, открытое через call 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 (значение)}, true) – user3197077