Computing.Net > Forums > Web Development > Javascript & Frames

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Javascript & Frames

Reply to Message Icon

Name: aldend123
Date: August 18, 2005 at 22:39:37 Pacific
OS: Win2000
CPU/Ram: P4 348
Comment:

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 javascript

top.frame1.location.href = 'website'
for example wont work.

what do I use?



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: August 19, 2005 at 10:57:13 Pacific
Reply:

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


0

Response Number 2
Name: aldend123
Date: August 19, 2005 at 19:31:00 Pacific
Reply:

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!


0

Response Number 3
Name: Michael J (by mjdamato)
Date: August 19, 2005 at 20:00:22 Pacific
Reply:

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>


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Javascript & Frames

Javascript cross-frame image swap www.computing.net/answers/webdevel/javascript-crossframe-image-swap/2582.html

HTML Frames and Google crawling www.computing.net/answers/webdevel/html-frames-and-google-crawling/3492.html

sequentially open windows in frame www.computing.net/answers/webdevel/sequentially-open-windows-in-frame/230.html