Hamzad
Hamzad

Reputation: 89

How can I find the title of parent window in javascript?

How can I find the title of parent window in javascript?

I use

 alert(window.parent.document.FormName);  

and

 alert(window.parent.document.title);

and

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

but the result wasn't true.

Upvotes: 1

Views: 8679

Answers (2)

Manish Nagar
Manish Nagar

Reputation: 1046

use this code for your solution

  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>
    

Upvotes: 1

JohnJohnGa
JohnJohnGa

Reputation: 15685

You are probably trying to access the title of the parent window from an iframe which is located on another server. For security reasons it is impossible.

Upvotes: 1

Related Questions