Crypto.randomUUID()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Crypto 接口的 randomUUID() 方法用于通过密码学安全的随机数生成器生成第四版 UUID

语法

js
randomUUID()

参数

无。

返回值

包含随机生成的、长度为 36 字符的第四版 UUID 字符串。

示例

js
/* 假定 self.crypto.randomUUID() 可用 */

let uuid = self.crypto.randomUUID();
console.log(uuid); // 例如 "36b8f84d-df4e-4d49-b662-bcde71a8764f"

规范

Specification
Web Cryptography API
# Crypto-method-randomUUID

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
randomUUID()

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

参见