Network Information API
Network Information API 將提供系統連線的相關資訊,如使用者裝置的現有頻寬,或目前的連線狀態。根據使用者的連線情形,可進一步選擇高解析度或低解析度的內容。此完整的 API 另包含 domxref("Connection") 介面,以及 Navigator
介面的單一屬性 ─ Navigator.connection
。
偵測連線變化
此範例將觀察使用者連線的變化。舉例來說,當使用者從高價位連線轉用低價位連線時,就會降低頻寬需求以避免連線費用暴增,並採用類似 Apps 受到警示的方法。
js
var connection =
navigator.connection || navigator.mozConnection || navigator.webkitConnection;
function updateConnectionStatus() {
alert("Connection bandwidth: " + connection.bandwidth + " MB/s");
if (connection.metered) {
alert("The connection is metered!");
}
}
connection.addEventListener("change", updateConnectionStatus);
updateConnectionStatus();
規範
Specification |
---|
Network Information API |
瀏覽器相容性
api.NetworkInformation
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
NetworkInformation | ||||||||||||
change event | ||||||||||||
downlink | ||||||||||||
downlinkMax | ||||||||||||
effectiveType | ||||||||||||
rtt | ||||||||||||
saveData | ||||||||||||
type | ||||||||||||
typechange event | ||||||||||||
Available in workers |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Non-standard. Check cross-browser support before using.
- Deprecated. Not for use in new websites.
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
api.Navigator.connection
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
connection |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.