views:

1896

answers:

3

How to get iframe src page title and then set main page title

+1  A: 

Unless the webpage is in the iframe is from the same domain as the containing page, it is impossible.

If they do have the same domain, then try the following:

document.title = document.getElementById("iframe").documentElement.title;
Marius
`contentDocument`. Except in IE6-7, where you have to fall back to the non-standard `contentWindow.document`. `documentElement` is the root html tag; the `title` property is on the HTMLDocument itself.
bobince
A: 

Granting that iframes src and the parent document src are the same domain:

Parent document:

<html>
<head><title>Parent</title>
<body>
   <iframe id="f" src="someurl.html"></iframe>
   <script>
       //if the parent should set the title, here it is
       document.title = document.getElementById('f').contentWindow.document.title;
   </script>
</body>
</html>

someurl.html:

<html>
<head><title>Child</title>
<body>
  <script>
       //if the child wants to set the parent title, here it is
       parent.document.title = document.title;
       //or top.document.title = document.title;

  </script>
</body> 
</html>
jerjer
A: 

In case you anyway want to do it using jquery, you can do it as following:

var title = $( "#frame_id").contents( ).find( "title").html( );
$( document).find( "title").html( title);

And pay attention as stated above, you can do it only when script running and page in the same domain, otherwise it's useless.

Artem Barger