JavaScript Frames

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
I can't figure out how to access a frame from inside the frame page. In my real script, I am trying to change the title of the window to that of a certain frame. I tried self.framename like I was told, but no luck, can anybody with experience help?
HTML:
html>
<head>
<script type="text/javascript">
if ( document.title =  ... .title  ) alert("True");
</script>
</head>
<frameset cols="25%,50%,25%">
  <frame name="framea" src="frame_a.htm">
  <frame name="frameb" src="frame_b.htm">
  <frame name="framec" src="frame_c.htm">

<noframes>
<body>Your browser does not handle frames!</body>
</noframes>

</frameset>

</html>
This is a modified version from this TryIt Editor from w3schools, I find it much easier.

Edit:
Thank you all who tried to help, the answer was self.framename.document.title, but it did not work is because the file loaded was from a remote server, so access was denied to JavaScript. Took me a while. A more accurate version of my script is:
HTML:
html>
<head>
<script type="text/javascript">
if ( document.title =  self.framea.document.title  ) alert("True");
</script>
</head>
<frameset cols="25%,50%,25%">
  <frame name="framea" src="http://yahoo.com">
  <frame name="frameb" src="frame_b.htm">
  <frame name="framec" src="frame_c.htm">

<noframes>
<body>Your browser does not handle frames!</body>
</noframes>

</frameset>

</html>
This got me an access denied error message. If anybody knows a way to do this, either with JavaScript or PHP, please tell me. Smart people don't use frames :p
 
Last edited:

quantum1

New Member
Messages
68
Reaction score
0
Points
0
Are you trying to change the title depending on what frame the cursor is in? That is, if the cursor is in frame a you want the title of the browser window to be the title of frame a?
 

Twinkie

Banned
Messages
1,389
Reaction score
12
Points
0
Noo, I am trying to change the name of the main window based on the title of frame a. I don't believe this is possible because framea is loaded from a remote server (Yahoo!).
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
If you are or want to use Firefox you can download the Firebug add-on and it will allow you to poke around the HTML DOM environment and mess with Javascript entities and so forth. That might help you figure out this and other stuff.
 

vol7ron

New Member
Messages
434
Reaction score
0
Points
0
Firebug isn't the best tool to use with Frames, only because not all of the DOM is documented in the tree and the ones that are aren't in alphabetical order.

Truth is, I'm not sure that you can do this. The problem wouldn't be because the page is on a remote server because the HTML of the page is readable (can be accessed) by any computer. The only thing that matters is the parent window of the frameset. The problem is that I don't think you can access the frames that way.

Does self.framename.document.title work? Generally, you'd want to use top.framename.document.title from within one of the frames themselves... I don't think you can do this in the html file that controls the frameset.
 

t2t2t

New Member
Messages
690
Reaction score
0
Points
0
I don't believe this is possible because framea is loaded from a remote server (Yahoo!).
Yep, you can't access content in a frame from remote server using javascript. It's because of security (Eg. sending data in cookies to another site)
 
Top