2012-10-15 3 views
0

상위 창에서 하위 창의 Java 스크립트 기능을 실행하려고합니다. 상위 창에서 URL을 변경 한 후에도 마찬가지입니다. 나는 다음과 같은 시도 :부모 창에서 url을 변경 한 후 부모 창에서 자식 창 Java 스크립트 함수를 실행하는 방법은 무엇입니까?

**Parent.html:** 

<html> 
    <head> 
    <title>Parent window document</title> 
    </head> 
    <body> 
    <script type="text/Javascript"> 
    function openChildWindow() 
    { 
     var s_url  = "child.html"; 
     var s_name = "ChildWindowDocument"; 
     var s_specs = "resizable=yes,scrollbars=yes,toolbar=0,status=0"; 
     var childWnd = window.open(s_url, s_name, s_specs); 
     var div  = childWnd.document.getElementById("child_wnd_doc_div_id"); 
     div.innerHTML = "Hello from parent wnd dddsfds"; 
    } 
    </script> 
    <input type="button" value="Open child window document" name="sss" onclick="openChildWindow()" /> 
    <div>Click me: nothing will happen.</div> 
    <div id="aaa" class="yourclass"> 
     <p>This is a paragraph with a <span>span</span> where the paragraph's container has the class. Click the span or the paragraph and see what happens.</p> 
     This sentence is directly in the div with the class rather than in child element. 
    </div> 
    <div>Nothing for this div.</div> 
    <a>dsfsd</a> 
    </body> 
</html> 

**child.html:** 

<html> 
    <head> 
    <title>Parent window document</title> 
    <script> 
    opener.document.body.onclick = function(e) { 
    var sender = (e && e.target) || (window.parent.event && window.parent.event.srcElement); 
    document.getElementById("id").value=sender.tagName; 
    } 
    </script> 
    </head> 
    <body> 
    <div id="child_wnd_doc_div_id">child window</div> 
    ID: <input type="text" id="id"/><br/> 
    Name: <input type="text" id="id"/><br/> 
    Xpath: <input type="text" id="id"/><br/> 
    CSS: <input type="text" id="id"/><br/> 
    </body> 
</html> 

분명히 내 개념은 : 나는 부모 창에 URL을 변경 한 후 자식 창 기능을 실행해야합니다.

답변

0

유일한 방법은 내가 참조 :

가 오프너의 언로드 이벤트를 관찰합니다. 화재가 발생하면 (짧은 시간이 지난 후에) onclick 함수 (그리고 onunlad 함수)를 재 할당하십시오.

물론 두 문서가 같은 도메인 아래에 배치 된 경우에만 작동합니다.

관련 문제