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".<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);

The script below displays a different alert, depending on the visitor's browser:<html>
<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!");
alert("It's time to upgrade your browser!");
</head><body onload="detectBrowser()">

W3School-JavaScript Browser Detection
創作者 以我為中心的宇宙 的頭像


以我為中心的宇宙 發表在 痞客邦 留言(0) 人氣()