Thursday, November 20th, 2008

Creating Custom Protocol Handlers With HTML 5 and Firefox

Category: Firefox, HTML

Via Myk Melez comes word that Firefox 3 supports HTML 5 web protocol handlers, which I had not realized before. These are really nifty:

javascript

  1. window.navigator.registerProtocolHandler("mailto",
  2.                                   "https://www.example.com/?uri=%s",
  3.                                   "Example Mail");

This code creates a protocol handler for www.example.com that makes mailto links direct the user to the www.example.com web application, inserting the link into the URL given replacing the %s value. The final argument is the title of the protocol handler to present to the user.

There are obviously security limitations around this:

Note: Web sites may only register protocol handlers for themselves. For security reasons, it’s not possible for an extension or web site to register protocol handlers targeting other sites…The URL template supplied when registering must be of the same domain as the webpage attempting to perform the registration or the registration will fail. For example, http://example.com/homepage.html can register a protocol handler for http://example.com/handle_mailto/%s, but not for http://example.org/handle_mailto/%s.

The user will be prompted on whether they want to allow this protocol handler:

Now, when the user clicks on a link that has a registered protocol handler, they will be prompted on how to work with it:

This feature is documented in the HTML 5 spec. You can find documentation on Firefox’s implementation here and here.

Posted by Brad Neuberg at 7:00 am
3 Comments

++---
2.9 rating from 15 votes

3 Comments »

Comments feed TrackBack URI

What would be the use for this if firefox is so annoying???

Comment by goathi — November 20, 2008

It would be a rarely used feature but I do see some utility to it if its a popular site (click here to launch the [insert name] game client)

Comment by TNO — November 20, 2008

@Goathi: The idea is to allow web applications to compete with desktop applications. Right now you can register a desktop email application like Outlook, for example, to handle mailto: links; why shouldn’t a user be able to do the same but have a web application like Yahoo Mail handle the link?

Comment by Brad Neuberg — November 20, 2008

Leave a comment

You must be logged in to post a comment.