onChanged()
event of the
downloads
API is fired when any of a
downloads.DownloadItem
's properties changes (except for
bytesReceived
).
The listener is passed a
downloadDelta
as a parameter — an object containing the
downloadId
的
downloads.DownloadItem
object in question, plus the status of all the properties that changed.
browser.downloads.onChanged.addListener(listener)
浏览器
.
downloads
.
onChanged
.
removeListener
(
listener
)
浏览器
.
downloads
.
onChanged
.
hasListener
(
listener
)
Events have three functions:
addListener(callback)
Adds a listener to this event.
removeListener(listener)
Stop listening to this event. The
listener
argument is the listener to remove.
hasListener(listener)
Check whether a given
listener
is registered for this event. Returns
true
if it is listening,
false
否则。
callback
A callback function that will be called when this event occurs. This function will be passed the following arguments:
downloadDelta
An
对象
表示
downloads.DownloadItem
object that changed, and the status of all the properties that changed in it.
downloadDelta
object has the following properties available:
id
An
integer
表示
id
的
downloads.DownloadItem
that changed.
url
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
url
.
filename
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
filename
.
danger
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
danger
.
mime
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
mime
.
startTime
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
startTime
.
endTime
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
endTime
.
state
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
state
.
canResume
可选
A
downloads.BooleanDelta
object describing a change in a
downloads.DownloadItem
's
canResume
状态。
paused
可选
A
downloads.BooleanDelta
object describing a change in a
downloads.DownloadItem
's
paused
状态。
error
可选
A
downloads.StringDelta
object describing a change in a
downloads.DownloadItem
's
error
状态。
totalBytes
可选
A
downloads.DoubleDelta
object describing a change in a
downloads.DownloadItem
's
totalBytes
.
fileSize
可选
A
downloads.DoubleDelta
object describing a change in a
downloads.DownloadItem
's
fileSize
.
exists
可选
A
downloads.BooleanDelta
object describing a change in a
downloads.DownloadItem
's
exists
状态。
BCD tables only load in the browser
Log a message when downloads complete:
function handleChanged(delta) {
if (delta.state && delta.state.current === "complete") {
console.log(`Download ${delta.id} has completed.`);
}
}
browser.downloads.onChanged.addListener(handleChanged);
注意:
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 贡献者