1

javascriptで親ウィンドウのタイトルを見つけるにはどうすればよいですか?

私が使う

 alert(window.parent.document.FormName);  

 alert(window.parent.document.title);

 alert(window.parent.parent.document.title);

しかし、結果は真実ではありませんでした。

4

2 に答える 2

1

ソリューションにこのコードを使用する

  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>
    
  2. 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>
    
于 2013-01-19T10:17:34.890 に答える
1

parent別のサーバーにあるからウィンドウのタイトルにアクセスしようとしている可能性がiframeあります。セキュリティ上の理由から、それは不可能です。

于 2013-01-19T10:11:16.360 に答える