2016-07-08 3 views
1

부모 윈도우에서 선언 된 함수를 호출하려면 어떻게해야합니까? window.open을 호출하여 새 창을 열었습니다. 새 창 내용이 그리드이고 그리드의 각 항목에 link/anchor가 있습니다. 각 항목의 내 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") 
} 

도움을 주시면 감사하겠습니다.

+1

http://www.tonybhimani.com/2011/10/16/javascript-controlling-a-popup-windows-parent-window/을 읽어 보셨습니까? – thepiercingarrow

+0

이미 작동하고 있습니다. 해결 방법은 새 창에 EventListener를 추가하는 것입니다. 예 : win.addEventLister ('click', function (value) {redirectToRecord (value)}, true) – user3197077

답변

1

부모는 시작 창을 참조해야합니다.

parent.method()은 메소드를 호출합니다. 그것은 동일한 도메인에 있어야하지만, 크로스 도메인 호출이 작동하지 않습니다. windiw.opener 도우미와

1

전화 부모 창 기능 :

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