2016-10-14 1 views
0

HTML에는 두 가지 기능이 있습니다. 하나는 경고 만있는 abc이고 다른 하나는 미리 정의 된 HTML 문자열로 채우기 window.open()을 사용하여 새 창을 만드는 것입니다. 부모 HTML에서 함수를 호출하고 싶습니다. parent.abc 및 window.parent.abc를 호출 해 보았습니다. 둘 다 작동하지 않습니다.부모로부터의 호출 함수

<html> 
<body> 
<button onclick="myfunction()" type="button">A new Window</button> 
<script> 
    var myWindow; 
    function abc() { 
     alert("abc"); 
    }; 

    function myfunction() { 
     var htmlholder = '<!DOCTYPE html>'+ 
        '<html>'+ 
        '<body>'+ 
        '<p>Here is another HTML<\/p>'+ 
       '<button type="button1" onclick="parent.abc()">Call parentabc<\/button>'+ 
        '<\/body>'+ 
        '<\/html>'; 

     myWindow = window.open("", "MsgWindow", "width=200,height=100"); 
     myWindow.document.write(htmlholder); 

    }; 

</script> 
</body> 
</html> 
+3

팝업/탭이'opener', 프레임은'parent' 있습니다. – Teemu

+0

설명해 주셔서 감사합니다. – user3707157

답변

3

부모 대신에 오프너를 사용해야합니다. 바이올린을 추가했습니다.

function myfunction() { 
     var htmlholder = '<!DOCTYPE html>'+ 
        '<html>'+ 
        '<body>'+ 
        '<p>Here is another HTML<\/p>'+ 
       '<button type="button1" onclick="opener.abc()">Call parentabc<\/button>'+ 
        '<\/body>'+ 
        '<\/html>'; 

     myWindow = window.open("", "MsgWindow", "width=200,height=100"); 
     myWindow.document.write(htmlholder); 

    }; 

https://jsfiddle.net/0txe2qvx/

+0

그것은 작동합니다. 고맙습니다. :) – user3707157

+0

@ user3707157 그런 다음 답변으로 표시 :) –