Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

storing dom path in a variable

Posted on 2006-11-20
5
Medium Priority
?
196 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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:
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…
Suggested Courses

971 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