Solved

storing dom path in a variable

Posted on 2006-11-20
5
187 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i count words? 2 42
would you please explain me the conditional part ? 4 21
Performance for Office 365 6 46
Fulfillment API php code sample 1 38
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

786 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