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 />

The registerContentHandler() method accepts three arguments: the MIME type to handle, the URL<br />

of the page that can handle that mime type, and the name of the application. For instance, to register a<br />

site as a handler of RSS feeds, you can use the following code:<br />

navigator.registerContentHandler(“application/rss+xml”,<br />

“http://www.somereader.com?feed=%s”, “Some Reader”);<br />

The first argument is the MIME type for RSS feeds. The second argument is the URL that should receive<br />

the RSS - feed URL. In this second argument, the %s represents the URL of the RSS feed, which the<br />

browser inserts automatically. The next time a request is made for an RSS feed, the browser will navigate<br />

to the URL specified and the web application can handle the request in the appropriate way.<br />

Firefox 2 allows only three MIME types to be used in registerContentHandler() :<br />

“ application/rss+xml ” , “ application/atom+xml ” , and “ application/vnd.<br />

mozilla.maybe.feed ” . All three do the same thing: register a handler for all RSS<br />

and Atom feeds.<br />

A similar call can be made for protocols by using registerProtocolHandler() , which also accepts<br />

three arguments: the protocol to handle (i.e., “ mailto ” or “ ftp “ ), the URL of the page that handles the<br />

protocol, and the name of the application. For example, to register a web application as the default mail<br />

client, you can use the following:<br />

navigator.registerProtocolHandler(“mailto”,<br />

“http://www.somemailclient.com?cmd=%s”, “Some Mail Client”);<br />

In this example, a handler is registered for the mailto protocol, which will now point to a web - based<br />

e-mail client. Once again, the second argument is the URL that should handle the request, and %s<br />

represents the original request.<br />

In Firefox 2, registerProtocolHandler() is implemented but does not work.<br />

The screen Object<br />

The screen object (also a property of window ) is one of the few JavaScript objects that have little to no<br />

programmatic use; it is used purely as an indication of client capabilities. This object provides<br />

information about the client ’ s display outside the browser window, including information such as pixel<br />

width and height. Each browser provides different properties on the screen object. The following table<br />

indicates the properties and which browsers support them.<br />

224

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

Saved successfully!

Ooh no, something went wrong!