PreferenceManager: thuộc tính colorScheme
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Thuộc tính chỉ đọc colorScheme của giao diện PreferenceManager trả về một PreferenceObject dùng để ghi đè tùy chọn của người dùng về color scheme của trang web.
Các cài đặt PreferenceObject.value hợp lệ cho colorScheme là dark và light.
Giá trị
Một PreferenceObject dùng để ghi đè tùy chọn của người dùng về color scheme của trang web.
Ví dụ
>Sử dụng cơ bản
Ví dụ này minh họa cách truy vấn color scheme ưu tiên của người dùng.
js
if (navigator.preferences.colorScheme.value === "dark") {
// The user prefers a dark color scheme.
} else {
// The user prefers a light color scheme.
}
Thông số kỹ thuật
| Specification |
|---|
| Media Queries Level 5> # color-scheme-attribute> |