Get Browser name and Version in JavaScript
Get Browser name and Version in JavaScript |
Hi Friends in this lesson we are going to learn how to Get Browser name and Version in JavaScript..
user the below JavaScript codes to Get Browser name and Version in JavaScript..
index.html
<script> // browser var nVer = navigator.appVersion; var nAgt = navigator.userAgent; var browser = navigator.appName; var version = '' + parseFloat(navigator.appVersion); var majorVersion = parseInt(navigator.appVersion, 10); var nameOffset, verOffset, ix; // Opera if ((verOffset = nAgt.indexOf('Opera')) != -1) { browser = 'Opera'; version = nAgt.substring(verOffset + 6); if ((verOffset = nAgt.indexOf('Version')) != -1) { version = nAgt.substring(verOffset + 8); } } // Opera Next if ((verOffset = nAgt.indexOf('OPR')) != -1) { browser = 'Opera Next'; version = nAgt.substring(verOffset + 4); } // EDGE else if ((verOffset = nAgt.indexOf('Edge')) != -1) { browser = 'Microsoft EDGE'; version = nAgt.substring(verOffset + 5); } // MSIE else if ((verOffset = nAgt.indexOf('MSIE')) != -1) { browser = 'MS Internet Explorer'; version = nAgt.substring(verOffset + 5); } // Chrome else if ((verOffset = nAgt.indexOf('Chrome')) != -1) { browser = 'Google Chrome'; version = nAgt.substring(verOffset + 7); } // Safari else if ((verOffset = nAgt.indexOf('Safari')) != -1) { browser = 'Apple Safari'; version = nAgt.substring(verOffset + 7); if ((verOffset = nAgt.indexOf('Version')) != -1) { version = nAgt.substring(verOffset + 8); } } // Firefox else if ((verOffset = nAgt.indexOf('Firefox')) != -1) { browser = 'Mozilla Firefox'; version = nAgt.substring(verOffset + 8); } // MSIE 11+ else if (nAgt.indexOf('Trident/') != -1) { browser = 'MS Internet Explorer 11+'; version = nAgt.substring(nAgt.indexOf('rv:') + 3); } // Other browsers else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) { browser = nAgt.substring(nameOffset, verOffset); version = nAgt.substring(verOffset + 1); if (browser.toLowerCase() == browser.toUpperCase()) { browser = navigator.appName; } } // trim the version string if ((ix = version.indexOf(';')) != -1) version = version.substring(0, ix); if ((ix = version.indexOf(' ')) != -1) version = version.substring(0, ix); if ((ix = version.indexOf(')')) != -1) version = version.substring(0, ix); majorVersion = parseInt('' + version, 10); if (isNaN(majorVersion)) { version = '' + parseFloat(navigator.appVersion); majorVersion = parseInt(navigator.appVersion, 10); } </script> <h3>Detect Web Browser in JavaScript</h3> <table cellpadding="3" cellspacing="0"> <tr> <th>Browser</th> <th>Version</th> </tr> <tr> <td><b style="color:red"><script>document.write(browser)</script></b></td> <td><b style="color:green"><script>document.write(version)</script></b></td> </tr> </table>
That's it how to Get Browser name and Version in JavaScript..Keep visiting This blog for more codes .Thank You...
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.