Web Hosting Talk







View Full Version : Is this Possible??????


chilliboy
12-10-2000, 01:52 PM
I was wondering if it is possible to do this.

I want to create a frameset where the title of the frameset changes according to the title of the 'content frame'.

ie get the frameset title to = the title of the 'content frame'.

If possible how??

Cheers

etLux
12-10-2000, 03:35 PM
Yes, this is possible.

It will work in IE 4 and later, and in NS 6 (though not in NS 4.X, as the object model is not truly dynamic).

You can change the title in a frameset by the simple expedient of inserting this in the content page...

<script>
parent.document.title = 'Whatever the title is...'
</script>

chilliboy
12-10-2000, 04:10 PM
Can I swing it around somehow so that the script is just in the frameset? - That way I just have one instance if the script (in the frameset that doesn't change).


From your example I guess it would be along these lines

Inserted in the frameset:

<Title>
<script>
contentframe.document.title
</script>
</Title>

Could you advise me if I'm along the right lines, and correct my code (I'm sure its wrong as it was an educated guess from someone uneducated in Javascript!!)

etLux
12-10-2000, 05:27 PM
Obviously, if you want the title to change with each content page -- then the script must be in each of the changing pages...

Why do it the hard way with a custom script ya gotta fiddle constantly from the frameset?

chilliboy
12-10-2000, 06:46 PM
Let me explain a little more, so you get the idea. I'm using a product from anaconda foundation, which produces various headline news searchs. When the results are produced you can get the links to open within a frameset. The top frame contains a 'back' button to go directly back to the search page on your site, and the bottom frame contains the content. Now while this feature is useful, when someone saves that page in there favourites the Title that is saved will always be that of the frameset - which is no use to the user. So what I want to do is have the Title of the content frame saved rather than that of the frameset. I would have thought the easiest way to do this would be to make the frameset title = to that of the content page. Hence my problem, and the reason I can't do it as you suggested.

Lawrence
12-10-2000, 07:38 PM
Untested, but something like this might work:

<script language="JavaScript">
function changetitle() {
parent.document.title = MainWindowName.document.title;
setTimeout ("changetitle()", 1000);
}
changetitle();
</script>

To be quite honest... I don't like that - it's like a perl script doing chat. Perhaps there's an event handler that you can use. Oh, and I haven't done JavaScript for a while, so I'm unsure on a few things (like in what units is the time for the setTimeout function?)

There is an OnLoad event, perhaps you can tie that to a frame or something? Maybe it will let you do:

<frame name="MainWindowName" src="whatever.html" OnLoad="changetitle()">

and then the script would be:

<script language="JavaScript">
parent.document.title = MainWindowName.document.title;
</script>

Anyway, just a few ideas, I'm not sure if they'll even work!

etLux
12-10-2000, 10:18 PM
If I follow your verbal description, chilliboy -- not sure on that -- Lawrence's simplest solution above would be best and most straightforward. Just having this in the changing page would grab the title of the content page and send it to the browser header...

<script>
parent.document.title = MainWindowName.document.title;
</script>

Every time the page loaded, it would switch the title.

(Lawrence, the unit of time for setTimeout is milliseconds.)

chilliboy
12-11-2000, 10:08 AM
I'm really having no joy with this - I've tried most of the above solutions but can only get the following to work.

- Insert this into the mainFrame (Frame with changing content):


This was your suggestion etLux. BUT - I can't use this method as the the mainFrame's content is not mine! (Expalined above).

I therefore need to have the script within either the topframe or the frameset.

Ive tried this in the frameset

<script type="text/javascript">
{
document.title = mainFrame.document.title;
}
</script>

and this in the top frame:

<script type="text/javascript">
{
parent.document.title = mainFrame.document.title;
}
</script>

Neither work. Maybe its my dire understanding of JS but I don't understand why this doesn't work, when inserting the afore mentioned code in the content frame does.

I've tried useing an 'onload' function and still no joy.

I really need help with this one.

etLux
12-11-2000, 04:02 PM
I think I need to see the actual code on this one -- there are a couple of things that could mess you up, depending how it goes together. If you post a URL, I'll be happy to have a look...

chilliboy
12-11-2000, 04:32 PM
Well I think I may have finally sorted it with this (placed in the frameset) :

<script type="text/javascript">
function checker(){
parent.document.title=parent.bottom.document.title
}
setInterval("checker()",20)
</script>

It works when I just tested it through DW 'view in browser'. Not sure really what the interval should be set to though to make it work every time - or if this will effect it.

etLux
12-11-2000, 07:33 PM
Programmers First Law: If it works, it must be right... lol.

The interval is in milliseconds (1/1000ths of a second) -- however, most browsers and systems don't read much below 30 milliseconds. 100 milliseconds is probably fine, considering the average "blink rate" (reaction speed) of the human retina is about 75 milliseconds.

Lawrence
12-11-2000, 10:29 PM
The setInterval one should work, but if it does then the setTimeout one should work too (must be something I'm overlooking with it, stick with your setInterval one anyway - it's a little neater).

I reckon you'd only want to refresh it every 5 seconds or something (ie: 5000 milliseconds).

But it's still ugly - like someone who keeps looking out the window to see if their friend has arrived rather than their friend just knocking on the door (etLux - feel free to comment on that analogy!)

If you could get an OnLoad event to work somehow, that would be MUCH better. But if you can't, you have no choice - so if that's the case stick with the setInterval.

etLux
12-11-2000, 11:58 PM
Lawrence, I concur: I do not care for the idea of having a timer whacking away constantly if there's no need for it. It's bad programming.

The onload= should, at least on surface, work.

However, sans seeing the actual page code, I can't really say much more without talking through my hat.