2016-07-08 18 views
1

親ウィンドウで宣言されている関数を呼び出すにはどうすればよいですか? 私は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") 
} 

ご協力いただきまして誠にありがとうございます。

+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 
} 
関連する問題