Created
March 16, 2015 15:13
-
-
Save dgerhardt/3b63c8659d78c0c50821 to your computer and use it in GitHub Desktop.
ARSnova Browser Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>ARSnova Brower Test</title> | |
<script> | |
(function () { | |
"use strict"; | |
var logNode; | |
var join = function (arr) { | |
var arrToStr = arr.length > 1 ? "<strong>" + arr[0] + ":</strong> " : arr[0]; | |
for (var i = 1; i < arr.length; i += 1) { | |
arrToStr += arr[i]; | |
if (i < arr.length - 1) { | |
arrToStr += ", "; | |
} | |
} | |
return arrToStr; | |
}; | |
var log = function () { | |
console.log(arguments); | |
logNode.innerHTML += join(arguments) + "<br />"; | |
}; | |
var checkForPrivacyMode = function () { | |
log("<h2>Cookies & LocalStorage</h2>"); | |
var privacyMode = false, | |
cookieEnabled = (navigator.cookieEnabled) ? true : false; | |
log("navigator.cookieEnabled", cookieEnabled); | |
try { | |
log("localStorage", !!localStorage); | |
localStorage.setItem("storageTest", 1); | |
localStorage.removeItem("storageTest"); | |
log("localStorage setItem/removeItem", true); | |
log('typeof navigator.cookieEnabled === "undefined"', typeof navigator.cookieEnabled === "undefined"); | |
//if not IE4+ nor NS6+ | |
if (typeof navigator.cookieEnabled === "undefined" && !cookieEnabled) { | |
document.cookie = "cookieTest"; | |
cookieEnabled = (document.cookie.indexOf("cookieTest") !== -1) ? true : false; | |
log("document.cookie", cookieEnabled); | |
} | |
} catch (e) { | |
log("localStorage error", e); | |
privacyMode = true; | |
} | |
if (privacyMode || !cookieEnabled) { | |
return false; | |
} | |
return true; | |
}; | |
var checkLang = function () { | |
log("<h2>Language</h2>"); | |
log("navigator.language", navigator.language); | |
var lang; | |
if (navigator && navigator.userAgent && (lang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) { | |
log("isAndroid", true); | |
log("userAgent lang", lang[1]); | |
} | |
}; | |
window.addEventListener("load", function () { | |
logNode = document.getElementById("log"); | |
log("navigator.userAgent", navigator.userAgent); | |
checkForPrivacyMode(); | |
checkLang(); | |
}); | |
})(); | |
</script> | |
</head> | |
<body> | |
<h1>ARSnova Browser Test</h1> | |
<div id="log"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Runnable at: https://jsfiddle.net/81ryngzb/