I would like to create a custom search provider for IE7 or IE8 that is not requesting a URL with the search string as a parameter, but calls a JavaScript function instead, passing the search string as an argument to the function. To get started, I tried something really simple in my search provider XML:
<Url type="text/html" method="get" template="javascript:alert(&开发者_开发问答quot;{searchTerms}");"/>
However, trying to add this search provider in IE7 throws an error: "Internet Explorer could not install this search provider. There was a problem with the search provider's information."
If I change the URL to something more conventional like "http://localhost/search.aspx?q={searchTerms}" it works, so I am fairly sure the problem really is the javascript: call.
I am aware that this is not really what the search provider feature was designed for, but for the specific case I'm working on (legacy client script-heavy intranet app with nested iframes and elaborate time-consuming initialization) it would be great to be able to use IE's search box to trigger a search in the app without navigating away from the currently displayed page. If there are other solutions to achieve this, I'd love to learn about them. The app itself is IE-only, so there is no need to discuss other browsers here.
The only solution I can think of is to use a search provider that adds the searchTerms
to the fragment component of the URI. You can then use setInterval
to parse window.location.hash
for the terms.
<Url template="http://example.com/absolute-path/#q={searchTerms}" type="text/html"></Url>
The downside to this is that your website has to be a "one page application" with a known URL because the search provider specification does not allow relative URLs in the template.
I've created a small demo page and provider:
- Navigate to http://jsbin.com/evoqu
- Enter "http://jsbin.com/ovajo" into the text field and click the "Add Search Provider" button
- Use the newly added search provider and notice that the search terms are displayed on the page.
You can view and edit the source for the demo page and provider here:
http://jsbin.com/evoqu/edit
http://jsbin.com/ovajo/edit
精彩评论