View Full Version : how to get iframe title
vb2all
09-05-2011, 09:39 PM
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 "
jscheuer1
09-06-2011, 05:06 AM
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:
<!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.
vb2all
09-06-2011, 06:40 AM
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
jscheuer1
09-06-2011, 09:26 AM
<!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>
vb2all
09-06-2011, 05:31 PM
<!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
jscheuer1
09-06-2011, 07:32 PM
Works here:
http://home.comcast.net/~jscheuer1/side/iframe_title/index_2.htm
vb2all
09-06-2011, 09:41 PM
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
jscheuer1
09-07-2011, 01:50 AM
<!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 : ( <font color="#FF0000" id="thetitle">title
from iframe</font>
)</font></b></p>
<p align="left"><b><font size="5">description : (
<font color="#FF0000" id="thedescription"> meta name="description" from iframe </font>
)</font></b></p>
<p align="left"><b><font size="5">keywords : (
<font color="#FF0000" id="thekeywords">meta name="keywords" from iframe </font>
)</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>
vb2all
09-07-2011, 02:27 PM
<!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 : ( <font color="#FF0000" id="thetitle">title
from iframe</font>
)</font></b></p>
<p align="left"><b><font size="5">description : (
<font color="#FF0000" id="thedescription"> meta name="description" from iframe </font>
)</font></b></p>
<p align="left"><b><font size="5">keywords : (
<font color="#FF0000" id="thekeywords">meta name="keywords" from iframe </font>
)</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
jscheuer1
09-07-2011, 05:24 PM
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/side/iframe_title/index_3.htm
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.