This JavaScript code does a great job of displaying information about your web browser. Information includes Browser Name, Version, your computer’s OS platform, and whether Java is enabled. This also shows how many pages you’ve visited and screen resolution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | document.write("<center></p><table border=1 cellpadding=2><tr><td>"); document.write("<center><b>", navigator.appName,"</b>"); document.write("</td></tr><tr><td><p>"); document.write("<center></p><table border=1 cellpadding=2><tr>"); document.write("</p><td>Code Name: </td><td><center>"); document.write("<b>", navigator.appCodeName,"</td></tr><p>"); document.write("</p><tr><td>Version: </td><td><center>"); document.write("<b>",navigator.appVersion,"</td></tr><p>"); document.write("</p><tr><td>Platform: </td><td><center>"); document.write("<b>", navigator.oscpu,"</td></tr><p>"); document.write("</p><tr><td>Pages Viewed: </td><td><center>"); document.write("<b>", history.length," </td></tr><p>"); document.write("</p><tr><td>Java enabled: </td><td><center><b>"); if (navigator.javaEnabled()) document.write("sure is!</td></tr><p>"); else document.write("not today</td></tr><p>"); document.write("</p><tr><td>Screen Resolution: </td><td><center>"); document.write("<b>",screen.width," x ",screen.height,"</td></tr><p>"); document.write("</table></tr></td></table><p></center>"); |
This helps you not rely on any JavaScript Frameworks to get browser details such as JQuery.browser or others. Someone at StackOverFlow wrote an excellent script to detect the browser using the duck-typing method.
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 | // Opera 8.0+ var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; // Firefox 1.0+ var isFirefox = typeof InstallTrigger !== 'undefined'; // Safari 3.0+ "[object HTMLElementConstructor]" var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && window['safari'].pushNotification)); // Internet Explorer 6-11 // Edge 20+ var isEdge = !isIE && !!window.StyleMedia; // Chrome 1 - 79 var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime); // Edge (based on chromium) detection var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1); // Blink engine detection var isBlink = (isChrome || isOpera) && !!window.CSS; var output = 'Detecting browsers by ducktyping:<hr>'; output += 'isFirefox: ' + isFirefox + '<br>'; output += 'isChrome: ' + isChrome + '<br>'; output += 'isSafari: ' + isSafari + '<br>'; output += 'isOpera: ' + isOpera + '<br>'; output += 'isIE: ' + isIE + '<br>'; output += 'isEdge: ' + isEdge + '<br>'; output += 'isEdgeChromium: ' + isEdgeChromium + '<br>'; output += 'isBlink: ' + isBlink + '<br>'; document.body.innerHTML = output; |