Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Dojo discover OS, browser,
<!DOCTYPE html>
<html >
<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>
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";
return "Your browser is version " + has(browser) + " <br/> your operating system is " + OS + " <br/> running on " + platform;
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);
<p id="browserName"></p>
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment