Forum Moderators: open
If the user is using Ns4.7 then the link provided should get disabled
Else
If he is using any other browser or even Ns4 ++
The link provided should be enabled
<html> <head>
<title>Browser detection</Title>
<Script Language="JavaScript">
browsername=navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {browsername="NS"}
else
{if (browsername.indexOf("Microsoft")!=-1) {browsername="MSIE"}
else {browsername="N/A"}};
browserversion="0";
if (navigator.appVersion.indexOf("2.")!=-1) {browserversion="2"};
if (navigator.appVersion.indexOf("3.")!=-1) {browserversion="3"};
if (navigator.appVersion.indexOf("4.")!=-1) {browserversion="4"};
if (navigator.appVersion.indexOf("5.")!=-1) {browserversion="5"};
if (navigator.appVersion.indexOf("6.")!=-1) {browserversion="6"};
</script>
<body>
<script language="javascript">
document.write(browsername+browserversion)
</script>
<a href= "Testing.html " >Clickable if in MSIE- Inactive if in NS4</a>
</body>
</html>
Can Anyone Give me a Substitute For this Script Please
Thnx
Regards
Ashish
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Test</title>
<script type="text/javascript">
<!--
var bname = navigator.appName;
if (bname.indexOf("Netscape")!= -1) {
bname = "NN";
}
else if (bname.indexOf("Microsoft")!= -1) {
bname = "IE";
}
else if (bname.indexOf("Opera")!= -1) {
bname = "OP";
}
else {
bname = "";
}
var bver = navigator.appVersion.match(/([0-9\.]+)/g);
if (bname == "") {
bver = "";
}
else if (bname == "IE") {
bver = getVerFromStr(bver[1]);
}
else {
bver = getVerFromStr(bver[0]);
}
function getVerFromStr(str) {
var ret = "";
var idx = str.indexOf(".");
if (idx!= -1) {
ret = str.substring(0, idx);
}
else {
ret = str;
}
return ret;
}
//-->
</script>
</head>
<body>
<div>
<script type="text/javascript">
<!--
if (bname && bver) {
document.open();
document.writeln(bname + " " + bver + "<br />");
document.writeln(navigator.appName + " " +
navigator.appVersion + "<br />");
if ((bname == "MSIE") ¦¦
(bname == "OP") ¦¦
(bver > 4)) {
document.writeln('<a href="Testing.html">' +
'Clickable if in MSIE \/ NS6\+ \/ Opera \- ' +
'Inactive if in NS4</a>');
document.close();
}
}
//-->
</script>
</div>
</body>
</html>
...however there is one major caveat...
The navigator.appVersion string is too inpredictable to be parsed easily...consider the values returned for three popular browsers...
Opera 7.20:
Opera 7.20 (Windows NT 5.1; U)
Firebird 0.6.1:
Netscape 5.0 (Windows; en-US)
IE 6:
Microsoft Internet Explorer 4.0 (compatible; MSIE 6.0; Windows NT 5.1)
...as you can see, with Opera there are two numbers in the string, with Firebird (and all Gecko family browsers, AKAIK) there is one number, and with IE there can be four or five or more numbers (e.g., sp1, NT service pack 5, i386)...
I have assumed that for IE the second number is always the actual version number, and for NN / OP the first number is. If these assumptions turn out to be wrong in practice, the function is broken (or at least inaccurate) in that case.
IMO, it is better just to use object detection instead of browser detection. Do something akin to what DrDoc posted, and check if the browser supports the objects you want to use, or in this case check for an object that only NN4 doesn't have, and base your ouput on that.
Jordan