Monday, August 23, 2010

Where's my reference?

So, where is this parameter "top" defined?

See last post.

I could not easily locate the parameter when I went the w3c website (and I quit trying to find it fairly quickly too). So, how do the folks at Mozilla know that they need to add this parameter to be available to programmers? I went to their website which is chock-full of excellent documentation to see if I could find information about top. Sure enough, I was able to find that window.top is documented.

window.top - Returns a reference to the topmost window in the window hierarchy.


That's quite useful.(Note: the code snippet that I found was simply "top.location.host". Why did I look up "window.top" first? Since "top" had not been defined in the scope of the current function, I assumed that the variable is available to the global object. The global object in the browser context is called "window".)

The documentation also states that this property is "DOM Level 0. Not part of any standard." Maybe that's why I didn't find it in the W3C standard? What does "DOM Level 0" mean? DOM Level 0 is sometimes referred to as the Legacy DOM according to wikipedia.

[L]imited facilities for detecting user-generated events and modifying the HTML document in the first generation of [JavaScript / JScript]


So, what is considered "Legacy DOM"? I looked here, but became concerned when I did not find a "top" property or a "window" property. So, I looked in my copy of JavaScript: The Definitive Guide (I've got the 3rd Edition which should date me, I suppose.) and got the same list. That is when I realized that I was looking in the DOM chapter and not the chapter on the Window object.

So, the answer to my initial question is that top is defined by the JavaScript language. Not the W3C DOM spec. Look in the JavaScript Reference!

Friday, August 20, 2010

Other People's Code

I find that I learn a lot by looking at other people's code... for better or for worse. I'm sure that is common. Some people have even stated that development is simply copying and pasting code from one place to another with tweaks. (I'm fairly certain that the statement was made in jest, but it is probably close to the truth for some.)

And so, today I was reading someone's code and I saw the following statement:

url: 'http://' + top.location.host + ...

I don't know much about DOM parameters, so the top variable is totally new to me. As with (probably) most web developers I use the Firefox browser with the Firebug add-on (1.5.4). So, it is simple to see what the value of top is. Open Firebug, go to the DOM tab, scroll down until you find 'top' in the tree, open each node until you find the value of top.location.host.

Alternatively, if you click on the small red button on the lower right with the white triangle, you will open an interactive console window. Type top.location.host in this window and the value of the variable is reported in the main console.

Google Chrome's Developer Tools can also return the value by simply typing the variable in the console window. (They even have statement completion... Fancy!)

I wanted to know a little more about this variable so, I went to Google and made the folowing search:

site:www.w3.org/DOM top

I got a sad collection of results. So, why do the browsers all contain this variable? That will be another question to answer along the way.

Greetings from the Foul Maw Cur

The goal of this blog is to archive my progress as a software developer. Currently, my language of choice is JavaScript. I have made a five year goal to become a master of the language. I have a long way to go.

I just recently moved into a development position working on a new Ext JS application. I am moving into this position from a QA role. Previously, I have developed some in Java, Ruby, Perl, and JavaScript.

With 13 years of experience, I am no longer a young IT worker. Also, I now have a family, so time is an entity with which I often battle.

Come along for the ride! I'll probably be documenting the solutions to problems that many others have encountered and solved, but, you never know... Perhaps, there will be something more...