getFileIcon()
function of the
downloads
API retrieves an icon for the specified download.
For new downloads, file icons are available after the
downloads.onCreated
event has been received. The image returned by this function while a download is in progress may be different from the image returned after the download is complete.
Icon retrieval is done by querying the underlying platform. The icon that is returned will therefore depend on a number of factors including state of the download, platform, registered file types and visual theme.
This is an asynchronous function that returns a
Promise
.
var gettingIcon = browser.downloads.getFileIcon(
downloadId
,
// integer
选项
// optional object
)
downloadId
An
integer
representing the ID of the download.
选项
可选
An options
对象
representing preferences for the icon to be retrieved. It can take the following properties:
size
可选
An
integer
representing the size of the icon. The returned icon's size will be the provided size squared (in pixels). If omitted, the default size for the icon is 32x32 pixels.
A
Promise
. If the request succeeds, the promise will be fulfilled with a string representing the absolute URL of the icon. If the request fails, the promise will be rejected with an error message.
BCD tables only load in the browser
This example logs the icon URL for the most recent download:
function gotIcon(iconUrl) {
console.log(iconUrl);
}
function onError(error) {
console.log(`Error: ${error}`);
}
function getIcon(downloadItems) {
if (downloadItems.length > 0) {
latestDownloadId = downloadItems[0].id;
var gettingIcon = browser.downloads.getFileIcon(latestDownloadId);
gettingIcon.then(gotIcon, onError);
}
}
var searching = browser.downloads.search({
limit: 1,
orderBy: ["-startTime"]
});
searching.then(getIcon, onError);
注意:
This API is based on Chromium's
chrome.downloads
API。
Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.
最后修改: , 由 MDN 贡献者