Perform a search using the search engine specified, or the default search engine if no search engine is specified.
The results will be displayed in a new tab, or if the
tabId
argument is given, in the tab identified by this.
To use this function in your extension you must ask for the
"search"
manifest permission
.
To get the installed search engines, use
search.get()
.
browser.search.search(
searchProperties
// object
)
searchProperties
对象
. An object with the following properties:
query
string
. The search query.
engine
可选
string
. The name of the search engine. If the search engine name you specify doesn't exist, the function throws an error. If this property is omitted the default search engine will be used.
tabId
可选
integer
. An optional identifier for the tab you want to execute the search in. If this property is omitted the search results will be displayed in a new tab.
None.
BCD tables only load in the browser
Search using the default search engine. The results will be shown in a new tab:
function search() {
browser.search.search({
query: "styracosaurus"
});
}
browser.browserAction.onClicked.addListener(search);
Search using Wikipedia. The results will be shown in a new tab:
function search() {
browser.search.search({
query: "styracosaurus",
engine: "Wikipedia (en)"
});
}
browser.browserAction.onClicked.addListener(search);
Search using Wikipedia. The results will be shown in the active tab:
function search(tab) {
browser.search.search({
query: "styracosaurus",
engine: "Wikipedia (en)",
tabId: tab.id
});
}
browser.browserAction.onClicked.addListener(search);
最后修改: , 由 MDN 贡献者