Technology Programming

The Browser Object Model

The most commonly used object within the Browser Object Model and which all browser support is window which is the object that represents the browser window. Almost everything that you have in the browser is a property or method of that object. Even the Document Object Model for the web page is attached as window.document.

It is so common that what you need will be attached to the window object that JavaScript allows you to omit it from the front of the reference in many cases and so a lot of people do not realise that it is there.


There are a couple of different ways of referencing the properties and methods of the window object though and one where the reference to window on the front isn't optional can be extremely useful. It is worth remembering that the windows object exists.

You can of course add your own properties and methods to the windows object at any time. The following are three ways of defining a property called myProperty belonging to the window object.

var myProperty; // assuming this is not inside a functionwindow.myProperty;window['myProperty'];
You can then access the property from anywhere within your page using the same reference (without the var for the first one). The third of these ways of referencing the property is particularly useful when it comes to being able to reference properties where part or all of the property name is defined by another property.

If you have a number of properties named x1, x2, x3 etc. and you have another property that contains the number off the end of the x property that you want to access you can access it using window['x'+y] which accesses the property directly without the overhead that using eval('x'+y) has.

This is one of the reasons why you should avoid using eval() in your code - since it is just an extremely inefficient way of achieving the same result as can be achieved far more efficiently another way.

Methods also attach to the windows object unless you specify an alternative object that you want to attach them to.

More of this Tutorial

SHARE
RELATED POSTS on "Technology"
Blitzerwarner: Could You Escape the Speed Cameras?
Blitzerwarner: Could You Escape the Speed Cameras?
What Makes a Perfect Web Design Company?
What Makes a Perfect Web Design Company?
Inside No-Fuss Products In Gaming Computers
Inside No-Fuss Products In Gaming Computers
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Free Music Players For Websites
Free Music Players For Websites
'See How NCP Tracks Down Fake Ration Card Holders'
'See How NCP Tracks Down Fake Ration Card Holders'
You Can Stop Panic Attacks in Just two Minutes
You Can Stop Panic Attacks in Just two Minutes
WordPress Blog to WP Site! A Journey to Online Success
WordPress Blog to WP Site! A Journey to Online Success
Videos will give your business portal an extra leverage
Videos will give your business portal an extra leverage
Excellent Ways To Make Weight Loss Work For You
Excellent Ways To Make Weight Loss Work For You
Five Notable Differences between National and International Logo Designs
Five Notable Differences between National and International Logo Designs
Who Should Your Phoenix Web Design Client Be?
Who Should Your Phoenix Web Design Client Be?
White Papers & Other Documents - including ALFLB
White Papers & Other Documents - including ALFLB
Google Analytics Tips
Google Analytics Tips
Want To Make Your Website Faster? Follow These Steps
Want To Make Your Website Faster? Follow These Steps
The Starting of Couture Apparel
The Starting of Couture Apparel
Choose Custom Website Design Services
Choose Custom Website Design Services
Choosing the Right Joomla CMS Developer
Choosing the Right Joomla CMS Developer
A Look at SQL Server Denali AlwaysOn
A Look at SQL Server Denali AlwaysOn
4 Tips to Choose the Perfect Flash Animation Course
4 Tips to Choose the Perfect Flash Animation Course

Leave Your Reply

*