The JavaScript Navigator object contains all information about the visitor's browser. We are going to look at two properties of the Navigator object:appName - holds the name of the browser
appVersion - holds, among other things, the version of the browser
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
The script below displays a different alert, depending on the visitor's browser:
appVersion - holds, among other things, the version of the browser
The variable browser in the example above holds the name of the browser, i.e. "Netscape" or "Microsoft Internet Explorer".
<html><body>
<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
</script>
</body></html>
The script below displays a different alert, depending on the visitor's browser:
<html>
<head>
<script type="text/javascript">
function detectBrowser(){var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer")
&& (version>=4)){
alert("Your browser is good enough!");
}
else
{
alert("It's time to upgrade your browser!");
}}
</script>
</head><body onload="detectBrowser()">
</body>
</html>
Reference:
W3School-JavaScript Browser Detection
全站熱搜
留言列表