Add Custom Search Engine Using JavaScript

I am trying to create a very simple site that uses the Google Chart QR API to generate QR codes. The code I use is pretty simple

<form id="QR" action="http://chart.apis.google.com/chart" target="QRwindow" method="POST">
  <h1>QR Code<br/>Generator</h1>
  <textarea autofocus name="chl"
  onkeypress="if(event.which==13&&!event.shiftKey){document.getElementById('cht').click();event.preventDefault();}"
  onkeyup="if(this.value.length&gt;2000) this.value=this.value.substring(0,1500)"></textarea>
  <div>QR size (px):</div>
  <input type="hidden" name="chld" value="|0"/>
  <input type="number" name="chs" value="250" min="50" max="275"/>
  <button type="submit" name="cht" id="cht" value="qr">Generate!</button>
</form>
<iframe name="QRwindow" id="QRwindow" width="275" height="275" frameborder="0" src="http://chart.apis.google.com/chart?chld=|0&chs=250&cht=qr&chl=Foo%20Bar"></iframe>

http://jsbin.com/fule/2/

What I would like to do is add a button that automatically allows the user to add a search engine with the following URL:

http://chart.apis.google.com/chart?chld=|0&chs=250&cht=qr&chl=%s

but I could not find a way to automatically add a search engine for the user. Of course, I understand that this can be a security risk, but there is also the opportunity to add a gmail handler as for mailto:, so I would suggest that a similar browser setting, such as adding a search engine, is possible (be it with user confirmation). Is this even possible?

+3
1

, XML-

window.external.AddSearchProvider('/linktoyourxmldoc.xml')

XML :

<?xml version='1.0' encoding='UTF-8'?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>QR creator</ShortName>
    <Description>Create a QR code.</Description>
    <Tags>qr</Tags>
    <Contact>youremail@email.com</Contact>
    <Url type="text/html" template="http://chart.apis.google.com/chart?chld=|0&amp;chs=250&amp;cht=qr&amp;chl={searchTerms}"/>
</OpenSearchDescription>

, .

: , &amp;.

opensearch. this.

, chrome, , chrome.

, :

<link rel="search" type="application/opensearchdescription+xml" href="/linktoyourxmldoc.xml" title="MySite Search" />
+2

All Articles