public
Created

Dojo discover OS, browser,

  • Download Gist
dojodiscover.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
<!DOCTYPE html>
<html >
<head>
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script src='dojo/dojo-release-1.8.0/dojo/dojo.js'></script>
<script>dojoConfig = {parseOnLoad: true}</script><script src='../_static/js/dojo/dojo.js'></script>
<script>
 
 
require(["dojo/has", // alias has API to "has"
"dojo/_base/array", // alias array api to "arrayUtil"
"dojo/dom", // alias DOM api to "dom"
"dojo/_base/sniff", // load browser-related has feature tests
"dojo/domReady!"],function(has, arrayUtil, dom, sniff, domReady){ // wait until DOM is loaded
 
function makeFancyAnswer(browser){
 
var OS = "You have an unknown Operating System";
var display = document.getElementById("showOS");
var platform = navigator.platform;
 
if (navigator.appVersion.indexOf("Win")!==-1) OS = "Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OS = "Mac OSX";
if (navigator.appVersion.indexOf("X11")!=-1) OS = "UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OS = "Linux";
 
 
if(has(browser)){
return "Your browser is version " + has(browser) + " <br/> your operating system is " + OS + " <br/> running on " + platform;
}else{
return "No";
}
}
 
arrayUtil.forEach(["ie", "mozilla", "ff", "opera", "webkit", "chrome"], function(n){
dom.byId("answerIs" + n).innerHTML = makeFancyAnswer(n);
});
 
 
/*function makeAtLeastAnswer(browser, version){
var answer = (has(browser) >= version) ? "Yes" : "No"; // is has(browser) greater than or equal to version? Yes if not No;
dom.byId("isAtLeast" + browser + version).innerHTML = answer;
}*/
 
 
/* makeAtLeastAnswer("ie", 7);
makeAtLeastAnswer("ff", 3);
makeAtLeastAnswer("opera", 9);
*/
 
});</script>
</head>
<body>
<p id="browserName"></p>
 
<dl>
<dt>Is this Internet Explorer?</dt>
<dd id="answerIsie"></dd>
<dt>Is this Firefox?</dt>
<dd id="answerIsff"></dd>
<dt>Is this Mozilla?</dt>
<dd id="answerIsmozilla"></dd>
<dt>Is this Opera?</dt>
<dd id="answerIsopera"></dd>
<dt>Is this WebKit? (Dojo 1.3)</dt>
<dd id="answerIswebkit"></dd>
<dt>Is this Chrome? (Dojo 1.3)</dt>
<dd id="answerIschrome"></dd>
</dl>
 
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.