Solved

storing dom path in a variable

Posted on 2006-11-20
5
193 Views
Last Modified: 2013-11-19
Hello all;

I currently have a very complex and multi-layered system in development.  It is necessarry from time to time to time to change a property of an object embedded in an iframe from another locaton.  The result is that i have big calling strings that look like this:

top.window.frames.content.window.frames.dockLayer.setDockOpacity();

What I want to be able to do is create a javascript variable that contains an object reference so that in script I can say something like this:

dockNoSession.setDockOpacirty ();

So, I really want to be able to reference the dom path "top.window.frames.content.window.frames.dockLayer" through a single variable.  Any way to do this?

Many thanks

Tom T
0
Comment
Question by:ttupper21
[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
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 17983249
You already stated the answer in your question.
Here is the answer:
<script>

var dockNoSession = top.frames.content.frames.dockLayer;
dockNoSession.setDockOpacity();

</script>



0
 

Author Comment

by:ttupper21
ID: 17983476
No, this doesn't work.  It tells me that dockNoSession is null or not an object unless the variable is local in scope.  That is, if I have a function, I MUST define the path variable locally.  If I declare the variable at a global level, then the browser rejects it.

I have verified this with a function as follows:

function adjustOpacity() {
  var dockNoSession = top.window.frames.content.window.frames.dockLayer;
  dockNoSession.setDockOpacity();
}

This works just fine.  However, the following will NOT:

var dockNoSession = top.window.frames.content.window.frames.dockLayer;

function adjustOpacity() {
  dockNoSession.setDockOpacity();
}

Merely moving the variable declaration to a global scope messes it up.  I need this global scope because if I wanted to declare it locally every time I used it, I would just use the direct call, like so:

top.window.frames.content.window.frames.dockLayer.setDockOpacity

What can be accounting for this strange scope behavior?
      
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17983510
The timing is the problem.
You can assign the global var first AFTER the dockLayer frame is loaded.
So put the global var assignment in that frame document onLoad event handler.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

751 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