Solved

storing dom path in a variable

Posted on 2006-11-20
5
180 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

11 Experts available now in Live!

Get 1:1 Help Now