Java Reference
In-Depth Information
Two functions in this page are responsible for
the aforementioned behavior. The first function,
geoSuccess() , is the callback function that
executes when the browser can successfully
retrieve your device's/computer's position:
function geoSuccess(position) {
var coords = position.coords;
var latitude = coords.latitude;
var longitude = coords.longitude;
 
The first statement in this function stores
position.coords in the coords variable to access the positional information with fewer keystrokes.
The second and third statements retrieve the latitude and longitude, respectively.
Now that you have the latitude and longitude, you assemble a message that contains this information
and display it to the user:
figure 8-4
var message = "You're at " + latitude + ", " + longitude
 
alert(message);
}
If you denied the page access to your position, or if the browser cannot obtain your position, the
geoError() callback function executes:
function geoError(errorObj) {
alert(errorObj.message);
}
This simple function simply uses the error object's message property to tell the user why
getCurrentPosition() failed.
 
the screen object
The screen object property of the window object contains a lot of information about the display
capabilities of the client machine. Its properties include the height and width properties, which
indicate the vertical and horizontal range of the screen, respectively, in pixels.
Another property of the screen object, which you use in an example later, is the colorDepth
property. This tells you the number of bits used for colors on the client's screen.
the document object
Along with the window object, the document object is probably one of the most important and
commonly used objects in the BOM. Via this object you can gain access to the HTML elements,
their properties, and their methods inside your page.
This chapter concentrates on the basic properties and methods that are common to all browsers.
More advanced manipulation of the document object is covered in Chapter 9.
 
Search WWH ::




Custom Search