04.11.2015 Views

javascript

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8: The Browser Object Model<br />

If this page is loaded into a web browser, it will redirect to www.wrox.com after a second. At that point,<br />

the Back button will be disabled and you won ’ t be able to navigate back to this example page without<br />

typing in the complete URL again.<br />

The last method of location is reload() , which reloads the currently displayed page. When reload() is<br />

called with no argument, the page is reloaded in the most efficient way possible, which is to say that the<br />

page may be reloaded from the browser cache if it hasn ’ t changed since the last request. To force a reload<br />

from the server, pass in true as an argument like this:<br />

location.reload();<br />

location.reload(true);<br />

//reload - possibly from cache<br />

//reload - go back to the server<br />

Any code located after a reload() call may or may not be executed, depending on factors such as<br />

network latency and system resources. For this reason, it is best to have reload() as the last line of code.<br />

The navigator Object<br />

Originally introduced in Netscape Navigator 2.0, the navigator object has become a de facto standard<br />

for browser identification on the client. Though some browsers offer alternate ways to provide the same<br />

or similar information (for example, window.clientInformation in IE and window.opera in Opera),<br />

the navigator object is common among all JavaScript - enabled web browsers. As with other BOM<br />

objects, each browser supports its own set of properties. The following table lists each available property<br />

and method, along with which browser versions support it.<br />

Property/Method Description IE Firefox<br />

Safari/<br />

Chrome<br />

Opera<br />

appCodeName<br />

The name of the browser.<br />

Typically ” Mozilla ” even in<br />

non - Mozilla browsers.<br />

3.0+ 1.0+ 1.0+ 7.0+<br />

appName Full browser name. 3.0+ 1.0+ 1.0+ 7.0+<br />

appMinorVersion Extra version information. 4.0+ — — 9.5+<br />

appVersion<br />

Browser version. Typically<br />

does not correspond to the<br />

actual browser version.<br />

3.0+ 1.0+ 1.0+ 7.0+<br />

buildID Build number for the browser. — 2.0+ — —<br />

cookieEnabled<br />

cpuClass<br />

Indicates if cookies are<br />

enabled.<br />

The type of processor used on<br />

the client computer ( “ x86 ” ,<br />

” 68K ” , ” Alpha ” , ” PPC ” , or<br />

” Other “ ).<br />

4.0+ 1.0+ 1.0+ 7.0+<br />

4.0+ — — —<br />

(continued)<br />

219

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!