Solved

Finding a frame by name

Posted on 1997-05-19
4
288 Views
Last Modified: 2012-05-04
How does one find a frame object in the frame/window hierarchy, given its name.  The frame may be top.frames[0], or top.frames[8].frames[4].frames[6].Obviously, window.open() can find a frame by name; how can some javascript do the same?
0
Comment
Question by:mkornell
  • 2
  • 2
4 Comments
 
LVL 3

Expert Comment

by:RM032397
ID: 1265602
No doubt you have a serious application in mind. Let me give you a warning - and I would be interested to hear from others with similar experiences.  

I find (in Netscape 3.0 which is my main development and test platform) that when testing applications with several frames, and  I am NOT talking DOZENS as implied by your question that after several reloads during the usual cycle of develop and test the following occurs:

I call it 'Frame Fatigue'. The frame structure just stops working. Frames that should load do not. That is it. The only cure is to kill the browser and fire it up anew.

Now that you know this I hope you may reconsider the extravaganza of frames.

Now as for your question, please specify what 'finding the frame' constitutes and what the circumstances are in which this finding exercise must take place. Is it for a game? If not then the reaction is better not to lose than to have to find.

You would have to write a loop that iterated through the frames array to its length. For each frame/window in the array you would test the length of its own frames array and recursively loop into it if the lenght is > zero.  The function MUST be recursive because you could not decide in advance how many levels to go down.

This started out a comment, but I think it just became an answer1
0
 
LVL 3

Accepted Solution

by:
RM032397 earned 100 total points
ID: 1265603
See above!
0
 
LVL 2

Author Comment

by:mkornell
ID: 1265604
I want to get the frame object for the desired frame, so I can do things to it.A trivial example:f = find_frame_by_name ("frame_named_fred");f.document.writeln ("<P><FONT color=red>Fred is red</FONT></P>");Your comments re: frame fatigue are noted.  I'm not actually creating any frame hierarchy that big.  Its more like frames[4].frames[2].I was hoping there was a built-in way to find the frame.  Guess I'll have to write the recursive function you described.
0
 
LVL 2

Author Comment

by:mkornell
ID: 1265605
For those interested, here is a bit of JS code that finds a frame by name.function findWindow (winRoot, strName) {
      var aWin
      var len
      var i

      if (winRoot.name == strName) {
            return winRoot
      } else {
            len = winRoot.frames.length
            for (i = 0; i < len; i++) {
                  aWin = findWindow (winRoot.frames[i], strName)
                  if (aWin != null) {
                        return aWin
                  }
            }
      }
      return null
}
use it as such:var win = findWindow (top, "frame_named_fred")if (win != null) {    win.document.writeln ("I found frame_named_fred")}
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 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

25 Experts available now in Live!

Get 1:1 Help Now