I am quite impressed with IE8 beta 2, annoying bugs aside. One feature of IE8 that is very useful is accelerators, I decided to give it a shot today to see if I could get one working and its surprisingly easy.
You can create an accelerator by writing an xml document in the OpenService Format Specification for Accelerators and making the file accessible from a website, then creating a button with an onclick handler that calls window.external.AddService(url_to_xml_file).
As a quick test I created an xml file to describe an accelerator for my blog similar to the following.
<?xml version="1.0" encoding="UTF-8"?>
<os:openServiceDescription
xmlns:os="http://www.microsoft.com/schemas/openservicedescription/1.0">
<os:homepageUrl>http://www.yoursite.com</os:homepageUrl>
<os:display>
<os:name>Blog with your site</os:name>
<os:icon>http://www.yoursite.com/favicon.ico</os:icon>
<os:description>Blog on your site easily</os:description>
</os:display>
<os:activity category="Blog">
<os:activityAction context="selection">
<os:execute action="http://www.yoursite.com/blog/add_entry.aspx" method="get">
<os:parameter name="title" value="{selection}" type="text" />
</os:execute>
</os:activityAction>
</os:activity>
</os:openServiceDescription>
The most notable tags are described below:-
- <os:activityAction context="selection">
The value 'selection' of the context attribute of this tag specifies that this accelerator will be available when the user selects a block of text, there are two other possible options:-
'document' - makes the accelerator available for the whole document.
'link' - makes the accelerator available when the user selects a link.
- <os:execute action="http://www.yoursite.com/blog/add_entry.aspx" method="get">
The action of the execute tag does the business of redirecting to, or in this case, accelerating to the add entry page of the blog service, we can do this via a http GET or POST as described by the method attribute.
- <os:parameter name="title" value="{selection}" type="text" />
You can add a collection of these parameters that will be either sent as GET or POST vars, depending what you set for the method of the execute tag above, {selection} is a placeholder for information that is retrieved from the page that we are accelerating from, there are many possible options here which I will not list as they are available on msdn accelerator docs.
Once this xml document is ready and uploaded all that is needed is a link to it from a html document like the one below.
<html>
<head><title>My Blog Accelerator</title></head>
<body>
<button id="installButton" onclick="window.external.AddService('my_accelerator.xml');">Add My Blog Accelerator</button>
</body>
</html>
The example above would require the html document to be in the same path as my_accelerator.xml.
And thats all there is to it, the documentation for developing accelerators can be found on msdn.