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.
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.
// 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
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// 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;
Mostly developers confuse about JavaScript array [] and object {}, so this tutorial will explain the difference in between JavaScript {} and [] and gives practical examples to demonstrate both array and object concepts. Similarly, we show you seven tips to optimize JavaScript for the better performance of your website.