OTPCredential: thuộc tính code
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Thuộc tính chỉ đọc code của giao diện OTPCredential chứa mật khẩu dùng một lần (OTP).
Giá trị
Một chuỗi chứa OTP.
Ví dụ
Đoạn code dưới đây kích hoạt luồng quyền của trình duyệt khi tin nhắn SMS đến. Nếu quyền được cấp, promise phân giải với đối tượng OTPCredential. Giá trị code được chứa sau đó được đặt làm giá trị của phần tử biểu mẫu <input>, sau đó biểu mẫu được gửi.
navigator.credentials
.get({
otp: { transport: ["sms"] },
signal: ac.signal,
})
.then((otp) => {
input.value = otp.code;
if (form) form.submit();
})
.catch((err) => {
console.error(err);
});
Note: Để giải thích đầy đủ về code, xem trang WebOTP API. Bạn cũng có thể xem code này như một phần của bản demo hoạt động đầy đủ.
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebOTP API> # dom-otpcredential-code> |