spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column17


Compatibility Issues

Developer News
HP to Microsoft: Thanks for Nothing
iPhone Remains Left Out as Android Scores Flash
The Year of Living the OpenSocial

We'll utilize the height and width properties of the screen object in our demonstrations. These properties are discussed later in the column. The following script segment prints the height and width of the screen:

document.write(screen.height, "<BR>", screen.width);

Despite the differences between Navigator and Explorer, the properties of the screen object are mostly comptabile with both browsers. However, remember that the screen object isn't supported by older browsers.

The easiest way to make sure the browser features the screen object, before attempting to utilize its properties, is to set the LANGUAGE attribute of the <SCRIPT> tag to "JavaScript1.2". This stops older browsers from executing the script. Here's an example:

<SCRIPT LANGUAGE="JavaScript1.2">
<!--

document.write(screen.height, "<BR>", screen.width);

// -->
</SCRIPT>

If you would like to access the screen object in a backward compatible script, simply set up an object detection routine:

<SCRIPT LANGUAGE="JavaScript">
<!--

if (window.event) {
  document.write(screen.height, "<BR>", screen.width);
}

// -->
</SCRIPT>

As you can see, the screen object is a property of the topmost window object. It is only necessary to specify the preceding window object unless you're checking whether or not the screen object exists.

Even though Netscape and Microsoft implemented screen as a property of the window object, it doesn't make much sense. The user's screen always has the same attributes. Therefore, if you try to access the screen object as a proprety of a different window object (e.g., the one of another frame, or an absolutely positioned element), its properties still hold the same values. Furthermore, it doesn't seem logical to present the user's screen as a child of a window. In fact, the screen should be the parent in this parent-child relationship.

As we mentioned, most properties of the screen object are supported by Navigator 4.0x and Internet Explorer 4.0x. Nevertheless, some properties behave differently between these two browsers. We'll explain the differences as we go on discussing the various properties.

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Gateway Launches New Core i7-powered FX-Series Gaming PCs · Review: Lenovo ThinkPad SL300 · EBay, Alternative Site Holiday Resources for Sellers


Created: April 7, 1998
Revised: April 7, 1998

URL: http://www.webreference.com/js/column17/compatibility.html