<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GizBuzz &#187; Tutorials</title>
	<atom:link href="http://gizbuzz.co.uk/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://gizbuzz.co.uk</link>
	<description>Technology, Computers, Web 2.0, Google, Microsoft, and just about anything else</description>
	<lastBuildDate>Thu, 29 May 2008 10:02:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Making your own OpenSearch plugins</title>
		<link>http://gizbuzz.co.uk/2007/making-your-own-opensearch-plugins/</link>
		<comments>http://gizbuzz.co.uk/2007/making-your-own-opensearch-plugins/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 16:48:15 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Featured Post]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://gizbuzz.co.uk/2007/making-your-own-opensearch-plugins/</guid>
		<description><![CDATA[Peter takes a look at how to create OpenSearch plugins for Firefox, allowing you to use any search system from your Firefox search bar.]]></description>
			<content:encoded><![CDATA[<p>You may notice that a while back, I did a post on <a href="http://gizbuzz.co.uk/2007/search-gizbuzz-from-the-firefox-2ie7-search-box/">adding Gizbuzz to your Firefox/IE7 search box</a>. You might have wondered how I actually got that to work.</p>
<p>Well, I&#8217;m actually going to write a quick tutorial on how you make OpenSearch plugins (which is what that Gizbuzz one was). Normally, my tutorials are the realm of Gizbuzz&#8217;s sister site <a href="http://fosswire.com/">FOSSwire</a>, but since this one has quite a lot of relevance to the web in general (not just free/open source software), I thought I&#8217;d put it on Gizbuzz.</p>
<p><a href="http://opensearch.a9.com/">OpenSearch is a standard</a> being pushed by Amazon&#8217;s research arm, A9.com. To create a search plugin, you simply need to write a really short XML file containing instructions to the web browser on how to perform the search. The search plugins currently are supported in both Firefox 2.0.x and Internet Explorer 7. Unfortunately, Microsoft&#8217;s implementation is sadly incomplete, so to retain full cross-browser support you can&#8217;t use all features of OpenSearch.</p>
<p><span id="more-605"></span></p>
<p>Start off by opening up a text editor. Not a word processor, just use something like Notepad (or a dedicated code editor if you have one). Paste in the following as a template:<br />
[xml]<br />
<opensearchdescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"><br />
<shortname>My test search</shortname><br />
<description>Searches a test website</description></opensearchdescription></p>
<inputencoding>utf-8</inputencoding> <url type="text/html" method="get" template="http://example.com/search?q={searchTerms}"></url>[/xml]Let&#8217;s have a look at each line in detail:</p>
<p>[xml]<br />
<opensearchdescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"><br />
[/xml]</opensearchdescription></p>
<p>This line starts off our document. Like the root <strong>&lt;html&gt;</strong> tag in a web page, it describes what type of document this is.</p>
<p>[xml num=2]<br />
<shortname>My test search</shortname><br />
[/xml]</p>
<p>This line identifies the &#8216;short name&#8217; of your search plugin. This is the name that will appear on the list of search providers and is the normal text used to identify this search plugin. Keep it nice and short and sweet (&#8216;Google&#8217;, &#8216;eBay&#8217; and &#8216;Gizbuzz&#8217; are all nice, short names for this).</p>
<p>[xml num=3]<br />
<description>Searches a test website</description><br />
[/xml]</p>
<p>This should be a slightly longer description of what exactly you are searching (for example &#8216;Gizbuzz Blog Archive&#8217;).</p>
<p>[xml num=4]</p>
<inputencoding>utf-8</inputencoding> [/xml]Unless you have a specific reason to change this, leave it as it is.[xml num=5]<br />
<url type="text/html" method="get" template="http://example.com/search?q={searchTerms}"></url><br />
[/xml]</p>
<p>This is the line that actually makes it all happen, and it&#8217;s the hardest line to set up (but still really easy). You need to fill the <strong>template</strong> element with a URL that will perform your search.</p>
<p>The easiest way to snag such a URL is to do this. Head over to the desired site and perform a search for something recognisable (like OPENSEARCHTEST). Now, copy the URL from your browser&#8217;s location bar and paste it in.</p>
<p>Simply replace <strong>OPENSEARCHTEST</strong> in the pasted URL with <strong>{searchTerms}</strong>, and let OpenSearch do the rest.</p>
<p>If you can&#8217;t see that in the URL of the search results page, you may have come across a site that uses a slightly different method of doing a search. I&#8217;m not going to go into how to work with these kind of searches in this tutorial, but I might follow up on this a bit later.</p>
<p>[xml num=6]</p>
<p>[/xml]</p>
<p>Finally, we close everything off. Save that file with a <strong>.xml</strong> extension and upload it onto a web server somewhere.</p>
<p>The one last step you probably want to do is to actually provide the ability to add your search plugin to a browser. There are two main ways to do this:</p>
<h3>Add it to the browser with metadata</h3>
<p>The first way is to add it to a web page&#8217;s metadata. In the <strong>&lt;head&gt;</strong> section of your page:</p>
<p>[html]</p>
<link href="http://example.com/yoursearchplugin.xml" rel="search" type="application/opensearchdescription+xml" title="My search plugin" /> [/html]Simply fill in the URL and a description of your plugin and then if you go to your site, you should notice the arrow on the search box will glow a different colour. Click this, and you should be able to add your new plugin!One potential pitfall &#8211; the URL for your plugin <strong>must</strong> be absolute (it must contain the <strong>http://</strong> and the full domain name as well as the path to the XML file).<br />
<h3>Add a button</h3>
<p>If you want your plugin to be more noticeable, you might want to make a button on your website, which, when clicked, adds the plugin. In your page, include the following JavaScript:</p>
<p>[js]<br />
function addSearchProvider() {</p>
<p>try {<br />
window.external.AddSearchProvider(&#8216;http://example.com/yoursearchplugin.xml&#8217;);<br />
}<br />
catch (e) {<br />
alert(&#8220;Currently, the search provider function requires either Firefox 2 or Internet Explorer 7.&#8221;);<br />
return;<br />
}</p>
<p>}<br />
[/js]</p>
<p>Now make a button which calls this JavaScript when clicked:</p>
<p>[html]</p>
<input value=" Add to search box! " onclick="addSearchProvider();" type="button" /> [/html]Once again, fill in your URL in the JavaScript. The same absolute URL pitfall applies here too.</p>
<h3>Finishing up</h3>
<p>Once you&#8217;ve built your OpenSearch plugin and you&#8217;re broadcasting it on a web page using either (or both) of the above methods, anyone using Internet Explorer 7 or Firefox 2 can add that search plugin. Once they have, they can just click the arrow on the search box, choose the new plugin and get searching straight away!</p>
<p>I think I&#8217;ve pretty much covered everything &#8211; apart from searches that use POST, and of course a couple of advanced topics (like how to add pretty icons to your search plugins). If people liked this, I&#8217;ll make sure to revisit these topics in a future tutorial!</p>
]]></content:encoded>
			<wfw:commentRss>http://gizbuzz.co.uk/2007/making-your-own-opensearch-plugins/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

