Jump to content

Iframe Src Title.


novartic

Recommended Posts

Sorry if this has been covered before, I did do a search and found nothing even though I did see something about this a while back.Now, what I am trying to do now is the following:A script that looks at the IFrame scr's title tag

<title>Page title</title>

Then takes this and puts it into the main pages title tag.

<title>Main Site Title Javascript('The IFrame title auto gets dumped here.')</title>

This should be a reacuring script that runs every time you navigate around within the IFrame.Any ideas? Regards,Dan.(PS. I hate Iframes and wished I didn't use them. :) )

Link to comment
Share on other sites

I have had a bash at it, and this is as far as I got.

<script type="text/javascript">function pagetitle(){var T = document.getElementById("myFrame");  if(T.contentDocument)    {T.title = T.contentDocument.body.offsettitle;  }}window.onload = pagetitle;</script>

Link to comment
Share on other sites

I think you actually want to change the page title and not the frame's title.I'm not used to working with frames (which I highly discourage), but I think this should work:

function pagetitle() {  var frame = document.getElementById("myFrame");  frame.onload = function() {	if(frame.contentDocument) {	  document.title = frame.contentDocument.title;	}  }}

Link to comment
Share on other sites

I don't know were im going wrong. Could I have some advice please :)

<HTML><HEAD><!-- Beginning of Page title --><!-- Note, this is shown on/in the IE window --><!-- <TITLE onload="sizeFrame()">Oakmead College of Technology: Home</TITLE>--><!-- <TITLE>pagetitle()</TITLE>--><!-- <TITLE pagetitle()></TITLE>--><!-- End of Page title. --><link href="Style%20Sheet.css" rel="stylesheet" type="text/css"><link rel="shortcut icon" href="favicon.gif" type="image/.gif"><link rel="icon" href="favicon.gif" type="image/.gif"><link rel="SHORTCUT ICON" href="/favicon.ico"><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">function sizeFrame() {var F = document.getElementById("myFrame");  if(F.contentDocument) {	F.height = F.contentDocument.body.offsetHeight+30;  } else {	F.height = document.frames["myFrame"].document.body.offsetHeight+40;  }}window.onload = sizeFrame;function pagetitle() {  var frame = document.getElementById("myFrame");  frame.onload = function() {	if(frame.contentDocument) {	  document.title = frame.contentDocument.title;	}  }}</script></head>

	<TR>	<!-- Beginning of Iframe -->	<!-- Note, when a new page is made, you must re-direct the src="destination" to the correct dir with the html file listed.-->				<TD class="Body" align="center" valign="top"><iframe height="100%" id="myFrame" onload="sizeFrame()" class="iframehight" frameborder="0" scrolling="auto" src="Page content's/Home Page layout/Home.htm"></iframe></TD>	<!-- End of Iframe -->	</TR>

Link to comment
Share on other sites

You have the pagetitle function defined, but you're not actually using it anywhere. You should probably call the pagetitle function at the end of the sizeFrame function, you really only need to run sizeFrame once, it doesn't matter if you overwrite the frame's load event after resizing it.

Link to comment
Share on other sites

You have the pagetitle function defined, but you're not actually using it anywhere. You should probably call the pagetitle function at the end of the sizeFrame function, you really only need to run sizeFrame once, it doesn't matter if you overwrite the frame's load event after resizing it.
So you mean like this?
<HTML><HEAD><!-- Beginning of Page title --><!-- Note, this is shown on/in the IE window --><!-- <TITLE onload="sizeFrame()">Oakmead College of Technology: Home</TITLE>--><!-- <TITLE>pagetitle()</TITLE>--><!-- <TITLE pagetitle()></TITLE>--><!-- End of Page title. --><link href="Style%20Sheet.css" rel="stylesheet" type="text/css"><link rel="shortcut icon" href="favicon.gif" type="image/.gif"><link rel="icon" href="favicon.gif" type="image/.gif"><link rel="SHORTCUT ICON" href="/favicon.ico"><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">function sizeFrame() {var F = document.getElementById("myFrame");  if(F.contentDocument) {	F.height = F.contentDocument.body.offsetHeight+30;  } else {	F.height = document.frames["myFrame"].document.body.offsetHeight+40;  }}window.onload = sizeFrame;function pagetitle() {  var frame = document.getElementById("myFrame");  frame.onload = function() {	if(frame.contentDocument) {	  document.title = frame.contentDocument.title;	}  }}window.onload = pagetitle;</script></head>

	<TR>	<!-- Beginning of Iframe -->	<!-- Note, when a new page is made, you must re-direct the src="destination" to the correct dir with the html file listed.-->				<TD class="Body" align="center" valign="top"><iframe height="100%" id="myFrame" onload="sizeFrame()" class="iframehight" frameborder="0" scrolling="auto" src="Page content's/Home Page layout/Home.htm"></iframe></TD>	<!-- End of Iframe -->	</TR>

sorry, im not that good with js. I learn when I see a patten in a correct way if that makes scene;/ :)

Link to comment
Share on other sites

No, just call it at the end of sizeFrame:

function sizeFrame() {var F = document.getElementById("myFrame");  if(F.contentDocument) {	F.height = F.contentDocument.body.offsetHeight+30;  } else {	F.height = document.frames["myFrame"].document.body.offsetHeight+40;  }  pagetitle();}

Link to comment
Share on other sites

How do I define this in the title part?

<HTML><HEAD><!-- Beginning of Page title --><!-- Note, this is shown on/in the IE window --><TITLE onload="pagetitle()">Oakmead College of Technology: Home</TITLE><!-- End of Page title. --><link href="Style%20Sheet.css" rel="stylesheet" type="text/css"><link rel="shortcut icon" href="favicon.gif" type="image/.gif"><link rel="icon" href="favicon.gif" type="image/.gif"><link rel="SHORTCUT ICON" href="/favicon.ico"><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">function sizeFrame() {var F = document.getElementById("myFrame");  if(F.contentDocument) {	F.height = F.contentDocument.body.offsetHeight+40;  } else {	F.height = document.frames["myFrame"].document.body.offsetHeight+40;  }  pagetitle();}window.onload = sizeFrame;function pagetitle() {  var frame = document.getElementById("myFrame");  frame.onload = function() {	if(frame.contentDocument) {	  document.title = frame.contentDocument.title;	}  }}</script></head><BODY BGCOLOR=#E7E7E7 onmouseover="window.status=''; return true"onmouseout="window.status='';return true"><!-- ImageReady Slices (index.psd) --><TABLE class="Table" WIDTH=900 align="center" CELLPADDING=0 CELLSPACING=0>	  <TR>		<!-- Beginning of Top_Banner Bar -->		   	<TD height="145" align="center" valign="top"> <IMG SRC="images/Top_Banner.jpg" WIDTH=900 HEIGHT=145 ALT="Top_Banner"></TD>	<!-- End of Top_Banner Bar -->			</TR>	<TR>			<!-- Beginning of Menu bar -->	<!-- Note, when adding or removing links, you MUST remove or add the following code chunk, <a href="filename.html">Link clicky</a> -->				<TD class="Menu" height="28" ALIGN=center VALIGN=middle><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><strong> 	 	<a href="index.htm">Home</a> | <a href="about.html">About Oakmead</a> | 	<a href="curriculum.html">Curriculum</a> | <a href="sixthform/" target="_blank">Sixth 	  Form</a> | <a href="parentsinformation.html">Parents Information</a> | <a href="studentinformation.html">Student Information</a> | <a href="governors.html">Governors</a> | <a href="exams.html">Exams</a> | <a href="vacancies.html">Vacancies</a> 	  | <a href="contact.html">Contact Us</a></strong></font></TD>	<!-- End of Menu bar -->	</TR>	<TR>			<!-- Beginning of Spacer Bar -->	   	 <TD height="16" ALIGN=center VALIGN=top> <IMG SRC="images/Spacer.jpg" WIDTH=900 HEIGHT=16 ALT=""></TD>	<!-- End of Spacer Bar -->		</TR>	<TR>	<!-- Beginning of Iframe -->	<!-- Note, when a new page is made, you must re-direct the src="destination" to the correct dir with the html file listed.-->				<TD class="Body" align="center" valign="top"><iframe height="100%" id="myFrame" onload="sizeFrame()" class="iframehight" frameborder="0" scrolling="auto" src="Page content's/Home Page layout/Home.htm"></iframe></TD>	<!-- End of Iframe -->	</TR>

Link to comment
Share on other sites

You don't put anything in the title tag, that function will run when the page loads so that's really all you need. When the page loads it calls the sizeFrame function, which calls the pagetitle function.

Link to comment
Share on other sites

  • 3 weeks later...
<HTML><HEAD><!-- Beginning of Page title --><!-- Note, this is shown on/in the IE window --><TITLE></TITLE><!-- End of Page title. --><link href="Style%20Sheet.css" rel="stylesheet" type="text/css"><link rel="shortcut icon" href="favicon.gif" type="image/.gif"><link rel="icon" href="favicon.gif" type="image/.gif"><link rel="SHORTCUT ICON" href="/favicon.ico"><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">function sizeFrame() {var F = document.getElementById("myFrame");  if(F.contentDocument) {    F.height = F.contentDocument.body.offsetHeight+30;  } else {    F.height = document.frames["myFrame"].document.body.offsetHeight+40;  }  pagetitle();}window.onload = sizeFrame;function pagetitle() {  var frame = document.getElementById("myFrame");  frame.onload = function() {    if(frame.contentDocument) {      document.title = frame.contentDocument.title;    }  }}</script></head>

:) I must be pink or may be spam but I still cant get this working in IE7.Sorry about this... :)

Link to comment
Share on other sites

The Javascript is set up correctly, if it's not working I'm not sure what to say. Maybe add a few alerts to see what's going on.

function pagetitle() {  alert("running pagetitle");  var frame = document.getElementById("myFrame");  frame.onload = function() {		alert("running frame onload handler");	if(frame.contentDocument) {	  alert("setting title to " + frame.contentDocument.title);	  document.title = frame.contentDocument.title;	}  }}

Link to comment
Share on other sites

I get both alerts.But no outcome.Also, when I use this script.

function sizeFrame() {var F = document.getElementById("myFrame");if(F.contentDocument) {F.height = F.contentDocument.body.offsetHeight+30;} else {F.height = document.frames["myFrame"].document.body.offsetHeight+40;}}window.onload = sizeFrame;

The page hight works fine.When I then add the extra line, it does not work.

function sizeFrame() {var F = document.getElementById("myFrame");if(F.contentDocument) {F.height = F.contentDocument.body.offsetHeight+30;} else {F.height = document.frames["myFrame"].document.body.offsetHeight+40;}pagetitle();}window.onload = sizeFrame;

Link to comment
Share on other sites

You're missing the onload action for the frame. Go back to the version with the alerts in it, there are 3 alerts there, not 2. If you only saw 2 it was because the if statement wasn't evaluating to true. Add the else from the other function to the function with the alerts, you can remove the alerts.

Link to comment
Share on other sites

Im really stumped by what you just said. O well...<script type="text/javascript">function sizeFrame() {var F = document.getElementById("myFrame"); if(F.contentDocument) { F.height = F.contentDocument.body.offsetHeight+30; } else { F.height = document.frames["myFrame"].document.body.offsetHeight+40; }pagetitle();}window.onload = sizeFrame;function pagetitle() { var frame = document.getElementById("myFrame"); frame.onload = function() { if else(frame.contentDocument) { document.title = frame.contentDocument.title; } }}</script></head>What I have modded is in the red...

Link to comment
Share on other sites

Look at this function:

function pagetitle() {  alert("running pagetitle");  var frame = document.getElementById("myFrame");  frame.onload = function() {		alert("running frame onload handler");	if(frame.contentDocument) {	  alert("setting title to " + frame.contentDocument.title);	  document.title = frame.contentDocument.title;	}  }}

You said you got "both alerts". There are 3 alerts there, not 2. If you only saw 2, then it never set the title. If that's the case then if(frame.contentDocument) was not true. Look at the sizeFrame function, you see that you have an else part to that same if statement, you have no else in the pagetitle function. You need to add the else to get the title a different way if frame.contentDocument doesn't exist. sizeFrame is doing the same thing, just with the size instead of the title.

Link to comment
Share on other sites

Im missing something here I thinks... Help :)

<HTML><HEAD><!-- Beginning of Page title --><!-- Note, this is shown on/in the IE window --><TITLE></TITLE><!-- End of Page title. --><link href="Style%20Sheet.css" rel="stylesheet" type="text/css"><link rel="shortcut icon" href="favicon.gif" type="image/.gif"><link rel="icon" href="favicon.gif" type="image/.gif"><link rel="SHORTCUT ICON" href="/favicon.ico"><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><script type="text/javascript">function sizeFrame() { var F = document.getElementById("myFrame"); if(F.contentDocument) {alert("running frame hight method 1"); F.height = F.contentDocument.body.offsetHeight+30; } else {alert("running frame hight method 2 as 1 is gay"); F.height = document.frames["myFrame"].document.body.offsetHeight+40; }alert("loading page title junk that dont work"); pagetitle();}window.onload = sizeFrame;function pagetitle(){alert("running pagetitle"); var G = document.getElementById("myFrame"); G.onload = function() {alert("running frame onload handler"); if(G.contentDocument) {alert("1 setting title to + G.contentDocument.title"); document.title = G.contentDocument.title; } else{alert("2 setting title to + document.frames['myFrame'].document.body.title"); G.title = document.frames["myFrame"].document.body.title; } }}</script></head>
Link to comment
Share on other sites

Hee is my little bash from scratch. lol

function pagetitle(){alert("running pagetitle"); var G = document.getElementById("myFrame"); if(G.contentDocument) { G.document.title = G.contentDocument.title; G.document.title = document.write(<title>"title"</title>); } }
Does not work though lol.
Link to comment
Share on other sites

You still don't have an else. Why is this hard to understand? Your function is checking if "G.contentDocument" is true, right? You see that line? That's checking for a certain feature in the browser. If the browser does not have that feature, your function is not doing anything. So it's only supporting a certain browser. Your original sizeframe function includes an else to that if statement to do something else if the browser does not support that feature. The pagetitle function does not have an else, if the browser does not support contentDocument then the function just stops. You need to add an else there and access the frame a different way.Look at how this function is set up:

function sizeFrame() {  var F = document.getElementById("myFrame");  if(F.contentDocument) {	...  } else {	...  }}

vs. this one:

function pagetitle(){  var G = document.getElementById("myFrame");  if(G.contentDocument)  {	...  }}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...