How to change the <title> when am using frames

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Xanthopoulos C.
Forum Newbie
Posts: 3
Joined: Thu Dec 07, 2006 2:33 am

How to change the <title> when am using frames

Post by Xanthopoulos C. »

Hi all,
I am sure you all know that when you are using frames to a webpage you are not able to change the <title> text when surfing from a frame to another for example "MyWebpage - Home" to "My webpage - Contact".
I am trying to find a way through php that I will be able to read a variable from the html file of the <iframe> and then printing it to the main's fraim <title>.
The problem is that I don't know a way to link those two files.
If there is a different solution, I will be glad to hear it.
Thank you all in advance
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Is there a reason to use frames? I personally hate Frames, and i'm sure i'm not alone. But you could use javascript to change the title if you really need to.

Code: Select all

document.title = 'New Title';
This wont be good for search engine results, and frames never where good for those either.
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

Frames are barely used anymore

i first learnt HTML using frames and found them clunky and disjointed

tables and CSS are much better for aligning your data
Xanthopoulos C.
Forum Newbie
Posts: 3
Joined: Thu Dec 07, 2006 2:33 am

Post by Xanthopoulos C. »

Thank you a lot for your time evilchris2003 and Zoxive
'm sure i'm not alone
I couldn't agree with you more :D. But as you said I have to use them because it is a part of my University's project.
document.title = 'New Title';
I want to "drill" the title of the page from the inner frame.
For example when I am using the menu link "contact" at the main frame with the target="innerframe" I would like the <title> of the page to change to "Webpage - Contact".
Another problem is that my menu is a .swf file so I can't just add a event OnClick="The javascript you gave me".
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

personally i use an include file for the head of all my pages (header.inc)

and call the page name like this where $page_title is a variable in the header

Code: Select all

$page_title = 'Webpage Contacts';
include ('./header.inc');
but i really dont see how with out JS you are going to allow the <title> tag to be altered
as what you are asking is client side and as is so often pointed out on this forum php is server side

just a thought assuming the user has to click a link to view that particular page
try an switch statement where if the user clicks a particular link set $page_title then use $_POST to return the title on the following page
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
// Pretty much you can do anything you want here, even pick the pages that fill the frame
$page_title = 'Contact';
$top_frame = 'pages/topper.php?somevar=just_for_fun';
$bottom_frame = 'index.php?page=contact';
?>
<!-- php page contact.php -->
<html>
<head>
	<title><?php echo $page_title; ?></title>
</head>
<!-- php page contact.php -->
<frameset cols="100%"> 
		   <frameset rows="61px,*">
 		<frame src="<?php echo $top_frame; ?>" scrolling="no" noresize>
			<frame src="<?php echo $bottom_frame; ?>" scrolling="auto" noresize> 
	</frameset> 
</frameset> 

</html>
Xanthopoulos C.
Forum Newbie
Posts: 3
Joined: Thu Dec 07, 2006 2:33 am

Post by Xanthopoulos C. »

Thank you a lot, problem solved with javascript

Code: Select all

top.document.title="Webpage - the_title_of_the_inner_frame";
//To every .htm file that opens to the inner frame
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Moving to client side.
Post Reply