[JavaScript] Détecter Windows 11 avec User-Agent Client Hints (Async / Await)
Rédigé par admin Aucun commentaireDétecter Windows 11 en JavaScript :
async function isWin11orLater() {
let reponse = false;
if (navigator && navigator.userAgentData) {
await navigator.userAgentData.getHighEntropyValues(["platformVersion"])
.then(ua => {
if (navigator.userAgentData.platform === "Windows") {
const majorPlatformVersion = parseInt(ua.platformVersion.split('.')[0]);
if (majorPlatformVersion >= 13) {
//alert("Windows 11 or later");
reponse = true;
} else {
reponse = false;
}
}
else {
reponse = false;
}
});
}
return reponse;
}
(async function() {
const test = await isWin11orLater();
if (test)
alert("is Windows 11 or + : true");
else
alert('is Windows 11 or + : false')
})();
Compatibilités des navigateurs en Mai 2022
Documentation : https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
Documentation : https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgentData