Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to apply XML OpenSearch

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to apply XML OpenSearch". In daily operation, I believe many people have doubts about how to apply XML OpenSearch. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to apply XML OpenSearch". Next, please follow the editor to study!

In fact, this is an application of OpenSearch, as long as you write the corresponding microformat xml file, you can develop the corresponding search box. Refer to the definition document of OpenSearch to get the basic xml format. For example, a typical search xml file can be specified in this way.

Utf-8

ShortName

Description

Favicon

The above xml file is easy to understand, except for the fixed xml root, the other definitions can be understood literally: InputEncoding specifies the search code, depending on the actual situation of the site, ShortName this is the short name of the search, such as "Google search" Description description of this search box, such as "Taobao Shopping search-only you can't think of it, you can't find the favicon of similar Image pages." Used to identify the search Url this is the most important parameter, specify the search link. It has many parameters, and the {searchTerms} parameter is generally used to specify the search term. The parameter type= "text/html" indicates that the page is returned (the browser will jump to this page), and if it is in another format, it will be opened using the appropriate default program (for example, type= "application/rss xml" will be opened using a RSS reader).

Just write the xml format of OpenSearch, and you can refer to its OpenSearch definition document for details. The following is to add this search to the page, which can basically be divided into two ways. They are adding link tags to the head of the page (similar to RSS) and adding them using Javascript (such as defining a button trigger). Adding the link tag is very simple, in the following format

Similar to RSS, rel and type are fixed, and we mainly specify href (the url path of the above xml, which starts with http:// to be safe) and title (that is, the short title of the search). In this way, open this page in Explorer and Firefox and you will see the corresponding menu

Using Javascript to add is more troublesome (maybe it will be a lot more so now). We will mainly use the browser extension, which has a window.external.AddSearchProvider parameter (detailed documentation) in Explorer. Typical invocation methods are as follows

Window.external.AddSearchProvider

Can be used under Firefox

Window.sidebar.addSearchEngine (

"http://who.am.i/search.xml", / * engine URL * /

"favicon.ico", / * icon URL * /

"ShortName", / * engine name * /

"Description"); / * category name * /

Parameters and examples are described in the sample code (official documentation). It is worth noting that Explorer's window.external.AddSearchProvider calling methods (details) have been "compatible" since the Firefox2 version. Then our corresponding Javascript code can be written like this (in order to be compatible with previous versions of Firefox2, add else if judgment, if you do not think it is necessary, you can not add it)

Function addEngine () {

If (window.external | | window.external.AddSearchProvider) {

Window.external.AddSearchProvider ('http://who.am.i/search.xml');

} else if (window.sidebar & & window.sidebar.addSearchEngine) {

Window.sidebar.addSearchEngine (

"http://who.am.i/search.xml",

"favicon.ico", / * icon URL * /

"ShortName", / * engine name * /

"Description"); / * category name * /

}}

In this way, the function can be registered with the click event of a link or button, and a confirmation box will pop up, as shown in the figure, after the user clicks OK, it will be added to the browser search box.

At this point, the study on "how to use XML OpenSearch" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report