且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在javascript中找到父窗口的标题?

更新时间:2023-10-19 22:28:52

将此代码用于您的解决方案

use this code for your solution

  1. pageMain.html

  1. pageMain.html

<html>
<head>
    <title>Parent Window</title>
</head>
<body>
<input type="text" id="data" value="23444" />
<a href="#" onclick="javascript:openChildWindow();">Open Child Popup window</a>
</body>
<script>
function openChildWindow() {
    window.open('page1.html','childWindow','width=400,height=400');
}
</script>
</html>

  • page1.html

  • page1.html

    <html>
    <head>
        <title>Child Window</title>
    </head>
    <body onload="initializeMainDiv();">
        <div id="mainDiv"></div>
    </body>
    <script>
    function initializeMainDiv() {
       alert( window.opener.document.title )
      }
      </script>
    </html>