Navigator.deviceMemory

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

deviceMemory 只读属性返回千兆字节为单位的大概的机器内存。这个值是一个2的次方数除以1024,舍去小数点的近似值。并且,上下边界也用来保护那些拥有非常低端或者高端设备的用户的隐私。

语法

const memory = navigator.deviceMemory
console.log ("This device has at least " + memory + "GiB of RAM.")

Value

A floating point number.

Specifications

Specification Status Comment
Device Memory 1
deviceMemory
Editor's Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
deviceMemory
Experimental
Chrome Full support 63Edge ? Firefox ? IE ? Opera Full support 50Safari ? WebView Android Full support 63Chrome Android Full support 63Firefox Android ? Opera Android Full support 46Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.