Screen Properties: Compatibility Issues - Doc JavaScript
Compatibility Issues
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.
Created: April 7, 1998
Revised: April 7, 1998
URL: https://www.webreference.com/js/column17/compatibility.html