By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,918 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

Frameset title tricks

P: 66
If I have a frameset page with a frame in it, how would I use JS to get the title of the framed document and set it as the title of the parent frameset page?

If that makes no sense, please ask for clarification.
Jan 21 '08 #1
Share this Question
Share on Google+
11 Replies


P: 66
Anyone have an idea about this?
Jan 22 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Do you want to set it from the framed page or the frameset?
Jan 22 '08 #3

P: 66
Do you want to set it from the framed page or the frameset?
I want to take the title from the framed page and set it as the browser window's title, to put it simply.
Jan 23 '08 #4

acoder
Expert Mod 15k+
P: 16,027
The reason why I asked was that if the framed page changes, do you now need to update the title?

To set the title from the framed page:
Expand|Select|Wrap|Line Numbers
  1. window.onload= function() {
  2.   parent.document.title = document.title;
  3. }
To set it from the frameset:
Expand|Select|Wrap|Line Numbers
  1. function changeTitle() {
  2.   document.title = window.frames[frameName].document.title;
Jan 23 '08 #5

P: 66
Because of the circumstances of the system I've set up, the frameset will reload every time the framed page reloads. And I need to set the title from the frameset page, but when I do[html]<frameset onload="changeTitle()" ... >[/html], it doesn't seem to work.

I basically need to set the page title, from the frameset page, as soon as or before the framed page loads. How would that be implemented? I'm really Javascript-dull, sorry. :x

The name of the frame is "main", by the way.
Jan 25 '08 #6

P: 66
By the way, I stuck an alert("firing"); in there and it showed up, so the function's being called, I guess the JS isn't right?
Jan 25 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Can I see your code? This code works:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <script>
  3. function changeTitle() {
  4.   document.title = window.frames["main"].document.title;
  5. }
  6. </script>
  7. <frameset cols="50%,50%" onload="changeTitle();">
  8.   <frame src="script.htm">
  9.   <frame name="main" src="script2.htm">
  10. </frameset>
  11. </html>
Jan 25 '08 #8

P: 66
[html]<script type="text/javascript">
function changeTitle() {

document.title = window.frames["main"].document.title;

}
</script>
</head>
<frameset rows="100%,*" onload="changeTitle();" frameborder="NO" border="0">
<frame name="main" src="http://mysite.com:8080/<?php echo $_GET['page']; ?>">
</frameset>[/html]

As you can see, there's only one frame involved, and it covers the entire page. It's part of a cloaked redirect system that would hide the ":8080" of a home web server, but I don't see how any of that would stop it from working.
Jan 25 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Are the frameset and frame pages from the same domain?
Jan 25 '08 #10

P: 66
No. Oh, it's XSS security, isn't it? Gah.
Jan 25 '08 #11

acoder
Expert Mod 15k+
P: 16,027
No. Oh, it's XSS security, isn't it? Gah.
Yes, you can't access pages from another domain. The workaround would be to use some server-side code to get the page and load it into the frame and then document.title would become accessible to the frameset page.
Jan 28 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.