Solved

storing dom path in a variable

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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…
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)

920 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

16 Experts available now in Live!

Get 1:1 Help Now