Solved

Javascript: access parent's frame

Posted on 2001-07-20
9
252 Views
Last Modified: 2010-05-18
This should be easy:

My index.html file:

<FRAMESET rowS="*,*">
  <Frame NAME="menu" SRC="menu.html" >
  <FRAMESET colS="*,*" title="bottomframe">
    <Frame NAME="display" SRC="file1.html">
    <Frame NAME="notepad" SRC="file2.html">
  </FRAMESET>
</FRAMESET>

In the "menu.html" file, I want to access the frame (either frame "display) with the following code:

    parent.display.document.location="..."

but it won't work.

What did I miss here ?

As I know, FRAMESET doesn't have a "name" property, and the property "title" failed to function in the following example:

    parent.bottomframe.display.document.location="..."



0
Comment
Question by:shapeless
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:ahosang
Comment Utility
Your code should work. How are you calling this statement? More code please.
0
 

Author Comment

by:shapeless
Comment Utility
in script:

1.function WriteMessage()
2.{
3.  alert("test1");    
4.  parent.menu.document.location="http://...";
5.  alert("test2");
6.  parent.display.document.location="http://...";
7.  parent.notepad.document.location="http://...";
8.  alert("test3");
9.}

in HTML:

<input type="button" onclick="WriteMessage();" value="Write">

Action:

When I clicked on the buttom [Write], the frame "menu" loaded a new page as expected. The "alert" function showed "test1", "test2", but not "test3". And neither the frame "display" or "notepad" loaded a new page (nothing happened).

Obviously, the function WriteMessage() was executed, and stopped between line 5~6.
0
 
LVL 12

Expert Comment

by:ahosang
Comment Utility
Maybe try to load the menu frame last since that is the script calling frame. It seems a weird timing issue, it works on my computer(IE 5.5 and NS 4.6), but maybe it stops because the script calling frame is being wiped out first. The syntax is OK though.
0
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
yo !!
think this will work....
at least for my case...:P

function goTop(url)
{
     if(parent.location != document.location)
          parent.location = url;
}

hope it helps...:)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:shapeless
Comment Utility
ahosang:

My original code of WriteMessage() was like this:

1.function WriteMessage()
2.{
3.  parent.display.document.location="http://...";
4.  parent.notepad.document.location="http://...";
5.}

That means, it didn't even have the line for menu. I added that and other "alert" statements just to debug.

Sendoh,

I believe that your code actually loads the new page to replace the entire page (parent), but doesn't load the new page to frame "display" or frame "notepad"(which is what I want). Do I miss something here?
0
 
LVL 3

Accepted Solution

by:
Sendoh earned 50 total points
Comment Utility
ops...
i read the question wrongly...:P
anyway, try this

1.function WriteMessage()
2.{
3.  parent.frames["display"].document.location="http://...";
4.  parent.frames["notepad"].document.location="http://...";
5.}

it should work...;)

hope it helps.

regards
Sendoh
0
 

Author Comment

by:shapeless
Comment Utility
ahosang:

My original code of WriteMessage() was like this:

1.function WriteMessage()
2.{
3.  parent.display.document.location="http://...";
4.  parent.notepad.document.location="http://...";
5.}

That means, it didn't even have the line for menu. I added that and other "alert" statements just to debug.

Sendoh,

I believe that your code actually loads the new page to replace the entire page (parent), but doesn't load the new page to frame "display" or frame "notepad"(which is what I want). Do I miss something here?
0
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
?? how come u post the comment 2 times ??
haha
0
 

Author Comment

by:shapeless
Comment Utility
Dear Sendoh,

I apologize for the duplicate posting. I have no idea how it happened. Most probably I hit a [back] button on the browser and the page was refreshed ....

But anyway your answer works nicely. Thanks a lot ... ;)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now