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 use OpenSearch in XML

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to use OpenSearch in XML, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Many modern browsers have a search box on the right side of the address bar, and Google search is installed by default. The following figure shows: 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. Like a typical search.

Many modern browsers have a search box on the right side of the address bar, and Google search is installed by default.

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 ('http://who.am.i/search.xml');

The link in the parameter is the content of the above link. 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.

Thank you for reading this article carefully. I hope the article "how to use OpenSearch in XML" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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