Results 1 to 10 of 10

Thread: how to get iframe title

  1. #1
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to get iframe title

    Is it possible, and if so how, to get iframe title


    how to the master page take the same title iframe which content

    ex :
    master page any title

    &

    iframe page by title " Good sit "

    How the master page take title iframe page " Good sit "

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    With javascript this can only be done for pages on the same domain. And, if testing locally in some browsers the pages have to be in the same folder:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    <iframe name="myIframe" id="myIframe" src="another.htm" onload="document.title=this.contentDocument? this.contentDocument.title : this.contentWindow.document.title;" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
    <script type="text/javascript">
    (function(el, w){
    	function loadFunc(e){
    		e = e || w.event;
    		var f = e.target || e.srcElement, fb = f.contentDocument || f.contentWindow.document;
    		document.title = fb.title;
    	}
    	if (w.addEventListener)
    		el.addEventListener('load', loadFunc, false);
    	else if (w.attachEvent)
    		el.attachEvent('onload', loadFunc);
    })(document.getElementById('myIframe'), window);
    </script>
    <br>
    <a href="yet_another.htm" target="myIframe">Yetti</a>
    </body>
    </html>
    Notes: There are simpler ways to go about this (it's old code I had lying around), but the pages still have to be on the same domain. If you need to do this cross domain, you need to use javascript and a server side language like PHP or asp. And that server has to be configured to allow it to open files from another domain.

    Oh, and I just noticed this doesn't work in Chrome, at least not locally even in the same folder. Just tested live though, and it does work in Chrome live.
    Last edited by jscheuer1; 09-06-2011 at 09:14 AM. Reason: add - Oh, and I just noticed . . .
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question can you see

    can you see egyview.com/test.htm

    I want this ( test.html ) take the title of iframe page (egyview.com )

    Notes : iframe page not fixed
    Last edited by jscheuer1; 09-06-2011 at 09:29 AM. Reason: formatting

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    
    </head>
    <body>
    <p align="center">I Need help</p>
    <p align="center">I want this ( test.html ) take the title of iframe page (
    <a href="http://www.egyview.com">http://www.egyview.com</a> ) </p>
    <p align="center">Notes : iframe page not fixed </p>
    <p align="center">
    <iframe name="I1" src="http://egyview.com/" width="622" height="234">
    Your browser does not support inline frames or is currently configured not to display inline frames.
    </iframe></p>
    <script type="text/javascript">
    document.getElementsByName('I1')[0].onload = function(){
    	document.title = window.frames.I1.document.title;
    };
    </script>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    Quote Originally Posted by jscheuer1 View Post
    Code:
    <!doctype html public "-//w3c//dtd html 4.01 transitional//en"
       "http://www.w3.org/tr/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="content-language" content="en-us">
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=windows-1252">
    
    </head>
    <body>
    <p align="center">i need help</p>
    <p align="center">i want this ( test.html ) take the title of iframe page (
    <a href="http://www.egyview.com">http://www.egyview.com</a> ) </p>
    <p align="center">notes : Iframe page not fixed </p>
    <p align="center">
    <iframe name="i1" src="http://egyview.com/" width="622" height="234">
    your browser does not support inline frames or is currently configured not to display inline frames.
    </iframe></p>
    <script type="text/javascript">
    document.getelementsbyname('i1')[0].onload = function(){
    	document.title = window.frames.i1.document.title;
    };
    </script>
    </body>
    </html>
    not work with me

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you very much
    Is it possible to bring (title, description, keywords) from the iframe page to home page

    As shown in this link: egyview.com/test2.htm
    Last edited by jscheuer1; 09-07-2011 at 01:49 AM. Reason: formatting

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <p align="left"><b><font size="5">title :&nbsp; (&nbsp;&nbsp;&nbsp;<font color="#FF0000" id="thetitle">title 
    from iframe</font>&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <p align="left"><b><font size="5">description :&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#FF0000" id="thedescription">&nbsp;meta name=&quot;description&quot; from iframe </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <p align="left"><b><font size="5">keywords :&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#FF0000" id="thekeywords">meta name=&quot;keywords&quot; from iframe </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <iframe name="I1" src="another.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
    <script type="text/javascript">
    ;(function(frame){
    	document.getElementsByName(frame)[0].onload = function(){
    		var d = window.frames[frame].document, dt, dd, dk;
    		document.title = document.getElementById('thetitle').innerHTML = (dt = d.title)? dt : 'Untitled';
    		document.getElementById('thedescription').innerHTML = (dd = d.getElementsByName('description')[0])? dd.getAttribute('content', 0) : 'No Description';
    		document.getElementById('thekeywords').innerHTML = (dk = d.getElementsByName('keywords')[0])? dk.getAttribute('content', 0) : 'No Keywords';
    	};
    })('I1');
    </script>
    <br>
    <a href="yet_another.htm" target="I1">Yetti</a><br>
    <a href="another.htm" target="I1">Bob</a><br>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Sep 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by jscheuer1 View Post
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    </head>
    <body>
    <p align="left"><b><font size="5">title :&nbsp; (&nbsp;&nbsp;&nbsp;<font color="#FF0000" id="thetitle">title 
    from iframe</font>&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <p align="left"><b><font size="5">description :&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#FF0000" id="thedescription">&nbsp;meta name=&quot;description&quot; from iframe </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <p align="left"><b><font size="5">keywords :&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="#FF0000" id="thekeywords">meta name=&quot;keywords&quot; from iframe </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    )</font></b></p>
    <iframe name="I1" src="another.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
    <script type="text/javascript">
    ;(function(frame){
    	document.getElementsByName(frame)[0].onload = function(){
    		var d = window.frames[frame].document, dt, dd, dk;
    		document.title = document.getElementById('thetitle').innerHTML = (dt = d.title)? dt : 'Untitled';
    		document.getElementById('thedescription').innerHTML = (dd = d.getElementsByName('description')[0])? dd.getAttribute('content', 0) : 'No Description';
    		document.getElementById('thekeywords').innerHTML = (dk = d.getElementsByName('keywords')[0])? dk.getAttribute('content', 0) : 'No Keywords';
    	};
    })('I1');
    </script>
    <br>
    <a href="yet_another.htm" target="I1">Yetti</a><br>
    <a href="another.htm" target="I1">Bob</a><br>
    </body>
    </html>
    Thank you very much
    But how do you show (title, description, keywords) in the source of the page

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In the source of what page? It's already in the source of the page in the iframe. You cannot change the source code of the top page using javascript.

    It does show the requested information on the top page when viewed in the browser:

    http://home.comcast.net/~jscheuer1/s...le/index_3.htm
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •