Access child window elements from parent window using Javascript

后端 未结 1 1231
萌比男神i
萌比男神i 2021-01-13 01:31

I need to access child window elements from parent window. I have written the sample snippets below.

Parent HTML:





        
相关标签:
1条回答
  • 2021-01-13 01:57

    I feel this is because of some security. You can try this way instead:

    <html>
    <head>
        <title>Parent</title>
        <style>
            div {
                float: left;
                cursor: pointer;
            }
        </style>
        <script type="text/javascript">
            var SubpopUpWin = "";
            var testUrl = "";
            function Opennew(passedURL){
                testUrl = passedURL;
                SubpopUpWin = window.open("popups.htm", '_blank', 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes');
    
    
            }
        </script>
    </head>
    <body>
        <div onclick="Opennew('http://www.google.com')">
            Google
        </div>
        <div onclick="Opennew('http://www.yahoo.com')">
            Yahoo
        </div>
        <div onclick="Opennew('http://www.bing.com')">
            Bing
        </div>
    </body>
    

    <html>
    <head>
        <title>Child</title>
        <style>
            div {
                float: left;
            }
        </style>
    
    
    
    </head>
    <body>
        <div>
            <div id="ifrm_title">
            </div>
            <div style="margin-top:20px">
                <iframe id="ifrm" src="" width="470" height="270" frameborder="0" style="margin-top: 34px" scrolling="no">
                </iframe>
                <script type="text/javascript">
    
            document.getElementById("ifrm").src = window.opener.testUrl;
    
        </script>
            </div>
        </div>
    </body>
    

    0 讨论(0)
提交回复
热议问题