Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to access a certain frame using javascript written in the frame-html document
frameset.html
.........|........|
...frame1.html....frame2.html
__________
|.frame1.|
|________|
|........|
|.frame2.|
|________|within frameset.html (which created both frames via HTML, naming them as pictured)
i want to access the frames via javascripttop.frame1.location.href = 'website'
for example wont work.what do I use?

It's been a while since I've done this, but I'm pretty sure.
First off, it will be easier if you name your frames. Add name="framename" within the frame tags so you can reference them by name.
Second, I gather that you are trying to refer to a frame from within the html document that creates the frameset. If this is the case, try document.framename.location.href=
If that doesn't work, I know there are plenty of tutorials out there. Hope this helps.
Michael J

ive tried all sorts of googling and found nothing
like within the frameset html doc
i put alert(document.location) and that alerts of my current location
yet trying
alert(______.location) using all sorts of various frame-accessing combinations, none of them work. (im using alert as a test)now i tried using that in one of the frames to access the other's location
so in frame1 document:
alert(top.frame2.document.location)
alert(top.frame2.location)
alert(frame2.document.location)
alert(document.frame2.location)
and nothing is working!

You must have an error somewhere, because your last example should have worked. I just tested it and it worked for me. Here is the source for the files I used, try it your self:
Filename (parent.htm):
======================
<HTML><HEAD></HEAD>
<FRAMESET ROWS="75%,*">
<FRAME SRC="top.htm" name="topFrame">
<FRAME SRC="bottom.htm" name="bottomFrame">
</FRAMESET></HTML>Filename (top.htm):
===================
<HTML><HEAD></HEAD>
<body>Top Frame</body></HTML>Filename (bottom.htm):
======================
<HTML><HEAD>
<script language=javascript>
function clickMe(source) {alert(source);}
</script>
</HEAD><body>Bottom Frame. Click the locations below:
<div onClick="clickMe(parent.location);"> - Parent</div>
<div onClick="clickMe(document.location);"> - This Frame</div>
<div onClick="clickMe(parent.topFrame.location);"> - Top Frame</div>
</body></HTML>

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |