The JavaScript Diaries: Part 7

By Lee Underwood

parent

This property is used with frames. It refers to the frameset of the window or frame which contains the current frame. We'll look at this in more detail later when we learn about frames.

self

This property is just another way of referring to the current window object. Either of the following would be correct:

window.close()

self.close()

Using the self property instead of the window property makes it easier to read the code as it's clear which window is being referred to in the script.

status

This property holds the value of the text in the status bar of the browser window. It's related to the defaultStatus property above. This property, however, only changes the status line until something else changes it or it returns to the default state. It can be used to give detailed information about the link the mouse is hovering over. As with defaultStatus property above, be aware that many users prefer to see the URL rather than a message in the status bar.

An example of its usage would be (all on one line):

<a href="index.html" onMouseOver="window.status='Return home';
  onMouseOut="window.status='';" return true;">Home</a>

In the link above, the portion return true; causes the browser to display the onMouseOver event instead of the link itself, which is what the browser does by default. The onMouseOut sets the status to an empty string, allowing it to return to the default status when the mouse is moved away from the link. This is not required in Internet Explorer but is necessary in Mozilla-based browsers (Netscape and Firefox). (We will look at events, e.g., onMouseOver, in a later session.)

top

This property is used with frames. It refers to the topmost window in the frameset. We'll look at this in more detail later when we learn about frames.

There is an interesting, simple script using the top property that can help prevent your site from appearing within someone's frames on their Web site. Many people design their site with a top frame and then load Web pages from other sites in the bottom frame. That way the visitor won't leave the original site. They also don't directly visit your Web site. To break out of these types of frames, place the script below in the <head> section of your Web pages.

if (top != self) {
  top.location = self.location;
}

Let's take a look at what's going on here. Remember, the self property is just another way of referring to the current window object. Here we have a basic if statement. It says that if the topmost window in the frameset is not equal to ( != ) the current window object, then make the location of the topmost window equal to the current window object. In other words, if this page is in a frame, remove the current page and place it in the current window, without a frame.

window

This property refers to the current window object. It's actually a synonym for the self property.

Conclusion

That about covers the commonly used window objects. In our next session we will take a detailed look at the methods and event handlers associated with the window object and see how they work together with the window objects.

This article originally appeared on WebReference.com.


Page 4 of 4

Previous Page
1 2 3 4
 

Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
  •  
  •  
  •  
Thanks for your registration, follow us on our social networks to keep up-to-date