How to add a new feed handler in Firefox 2.0

| | Commenti (6) | TrackBack (0)

Firefox 2.0 is out... uhm? what are you saying? what a great news?... oh yeah, but this isn't the main topic of this post.

As someone of you probably remember, on June I made a few tests with Firefox 2.0 Bon Echo 3 focused on how the new Firefox handles feeds.
Firefox 2 gives you full control over Web feeds, showing you a preview and letting you choose how you want to subscribe.

At the end of the tests I wrote an article showing how is possible to add a new content handler, aka web aggregator, in Firefox 2.0... it was digged too!
Since Firefox 2.0 was not yet released at the time the article was written, I didn't know that there was an easier way to add an content handler without tweaking by hand Firefox registry.

Using registerContentHandler() javascript function is possible to add with just one click a new feed handler... how? Let me show you.


Adding a new feed handler to Firefox 2.0 with registerContentHandler()


registerContentHandler() is a JavaScript function that allows you to register a new content handler in Firefox 2.0.
It accepts 3 required params:



mimeType
the content mime type.
For a feed must be application/vnd.mozilla.maybe.feed.
uri
the content handler URI.
%s can be used as a placeholder for the resource URI.
title
the content handler Title

Once again, let's use Rmail as example.
Rmail add-new-subscription URI is (always the same) http://www.r-mail.org/bm.aspx?rss=%s while content handler title is Rmail.
Thus, the final JavaScript should looks like the following.

navigator.registerContentHandler('application/vnd.mozilla.maybe.feed',
'http://www.r-mail.org/bm.aspx?rss=%s',
'Rmail');

You can put/call this JavaScript function where everywhere in a HTML page, for example as a link (as Netvibes did)...


Example 1.


Look & feel


Click here and add Rmail


Code

<p>
<a href="javascript:window.navigator.registerContentHandler('application/vnd.mozilla.maybe.feed',
'http://www.r-mail.org/bm.aspx?rss=%s','Rmail');">Click here</a>
and add Rmail
</p>

... you can put it into a form button...


Example 2.


Look & feel



Code

<p>
<input type="button" name="add" value="Click here and add Rmail"
onclick="window.navigator.registerContentHandler('application/vnd.mozilla.maybe.feed',
'http://www.r-mail.org/bm.aspx?rss=%s','Rmail');" />

</p>


or include it into a JavaScript function and call it anywhere in the page (as Randy did).


Example 3.


Code

<script type="text/javascript">
function subWith()
{
navigator.registerContentHandler('application/vnd.mozilla.maybe.feed', 'http://www.r-mail.org/bm.aspx?rss=%s', 'Rmail');
}

</script>
<input type="button" name="add" value="Click here and add Rmail"
onclick="function subWith();" />


More power to registerContentHandler()


This tutorial might be closed here, but the real reason why I wrote this post is to show how is possible to add more power to registerContentHandler() with a few JavaScript lines.


The idea comes from this post where Randy shows a button to add Rmail as a new content handler.
In a comment pat asks which is the best technique between Randy's magic button (see example 2 and example 3) and my tutorial.


This is Randy's answer.



Pat,
Simone's technique is actually superior as it also includes the email address. I'm working on making that possible too!
Randy


Don't worry Randy, I will give you an help! :D


The only difference between my code and Randy's code is that I used the following Rmail subscription string (please note the mailto param)

http://www.r-mail.org/bm.aspx?rss=%s&mailto=YOUR_EMAIL

instead of

http://www.r-mail.org/bm.aspx?rss=%s

Thus, what we should do is find a way to allow user to type its own email address and append it to the content handler URI.


My first idea was to create a new input text field. It's better than using other thechniques such as JavaScript input boxes since the field can be easily filled with a server side programming language in a more complex site, can be validated and you can re-use in thousand ways.
While I was writing the code, I decided to do a little more. Why not creating a script that allows developers to add custom arguments to a content handler URI instead of a single one? Rmail just needs a mailto param but other readers may need mail and user...


This is what I wrote!


The following script allows you to register a new content handler in Firefox 2.0 just calling a simple function.
In addition, you can create as many form field as you wish calling them name="args". For each field, the script will collect its value and if the field isn't empty, will appends the value to the content handler URI.


Let's see an example. Again, I will use Rmail and I will show you how it's easy to append your personal email to the URI.


Example 4.

<!-- include the script -->
<script type="text/javascript" src="firefox2-registerFeedHandler.js"></script>

<!-- add as many field as you wish.
Each field called 'args' will be appended to content handler URI.
The argument name will be its unique form Id, the value the field value.
-->
<input type="text" name="args" id="email" value="" /><br />

<!-- call the function, use subWith(true) instead of subWith()
to collect form fields.
-->
<input type="button" name="subWith" onclick="subWith(true);" value="Make Rmail your Firefox RSS handler" />


First you must include the script.
Don't forget to customize chUri and chTitle variables, as written at the top of the javaScript file.


Then add an input text field for each argument you wish to append to the URI. You can also use hidden inputs to pass hidden values.
Don't forget to call them args or the script will not work.


Now call the subWith() function. You can use a link, a button or a common JavaScript event.

Enjoy the confirmation dialog! :D

Add new handler confirmation dialog



Try the example live:




Type you email and



The JavaScript file is available here.
Download it or copy it into your web site but please, don't change credits. ;)

0 TrackBacks

Listed below are links to blogs that reference this entry: How to add a new feed handler in Firefox 2.0.

TrackBack URL for this entry: http://www.simonecarletti.com/mt4/mt-script-tb3.cgi/507

6 Comments

gestibar said:

nice :)
;))

Frank Lynch said:

This is awesome, just one quick question - how can I remove a feed reader after its been added using the methods described above?

Frank Lynch said:

to answer my own question, just go into your prefs.js (somewhere like ~/.mozilla/firefox/absn66nz.default/prefs.js & remove the related entries. Be sure to remove a prefs.js~ if your editor creates one.

Thanks Frank for your feedback!
It makes this article more complete. :)

Logan said:

Hi Simone. One question: do you know how to set the default feed handler to a desktop RSS reader using a script or some external method?

I know how to do it manually (and of course it's not hard) but I want something I can do automatically for users of my program.


...any ideas??

Thanks!

Logan said:

Aha! Thanks to Paul Roub for pointing me in the right direction:

browser.feeds.handlers.default: client
browser.feeds.handlers.application: c:\path\to\app

Leave a comment

Disclaimer:
SPAM comments or messages posted just in order to take advantage of search engines popularity might be removed without any notice.
Comments are filtered against Akismet antispam service, keyword filters and blacklists.

FeedBurner Network

Questo blog è parte del network Web Marketing e Motori di ricerca (a FeedBurner Network).

Scopri di cosa si tratta (sì, lo so, il post introduttivo è un po' lungo...)

Non perderti gli aggiornamenti

Feed Sottoscrivi il feed

Non conosci i feed RSS? Hai paura che sia una fregatura? Questa breve presentazione fa al caso tuo... prenditi 5 minuti, è divertente! :)

servizi e curiosità

Add to Technorati Favorites
Aggiungi il blog al tuo elenco di preferiti su Technorati.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 4.1