Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Finding a frame by name

Posted on 1997-05-19
4
Medium Priority
?
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

661 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