473,585 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Browser Check

Is this a very good browser check?

<html>
<head>
<title>wB.htm </title>
<script type="text/javascript">
var adBtype = "??";
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
} else if (document.all) {
adBtype = "IE4";
} else if (document.layer s) {
adBtype = "NS4";
}
alert(adBtype);
}
</script>
</head>
<body onload="wB()">
<body>
</html>

Opera 6.01 returns "IE5+"; don't know about others...
Jul 20 '05 #1
6 2435
"McKirahan" <Ne**@McKirahan .com> wrote in message
news:Jm9%b.5668 6$Xp.269424@att bi_s54...
Is this a very good browser check?


<script cut>

See: http://jibbering.com/faq/#FAQ4_26
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: http://www.andrewu.co.uk/about/conta...=newsgroup_clj
Jul 20 '05 #2
"McKirahan" <Ne**@McKirahan .com> writes:
Is this a very good browser check?
No. I can say that without reading, because browser checks are almost
invariably not good, no matter how efficient they are :).

(Remember DOCTYPE, it is required by HTML)
var adBtype = "??";
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
Or Opera 6 or ....
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
Or Opera 6 (in IE mode) or Opera 7 or ...
} else if (document.all) {
adBtype = "IE4";
Or WebTV or ....
} else if (document.layer s) {
adBtype = "NS4";
Or OmniWeb or ...
Opera 6.01 returns "IE5+"; don't know about others...


Not knowing about others is *the* problem with browser detection.
Optimistically it is hard work to become familiar with all browsers,
realistically, it is quite impossible. You will invariably miss some
browsers that are in actual use, and will most likely badly
misrepresent future browsers.

The way to make scripts usefull across as many browsers as possible
are:
1) Use standards! It gives you the best chance of forward compatability.
2) Use object/feature detection, not browser detection, to make fallbacks
for non-standard-compliant browsers.

Object detection coulde be:

var elem;
if (document.getEl ementById) {
elem = document.getEle mentById(id);
} else if (document.all) {
elem = document.all[id];
} else if (document.layer s) {
elem = document.layers[id];
} else {
elem = null;
}

Before using a standard feature that some browsers are known to be
incompatible with, you test for its existence. If it doesn't exist,
you test for the existence of some other feature that might (or might
not) be used instead. Notice that the above code doesn't care whether
it is IE 5+ or NS 6+ or whatever. It is not perfect code! There are
cases where it fails too, which further testing could fix. And some
that it can't (some browsers are just broken, or doesn't have
Javascript enabled).

It is important to realize that old browsers that nobody uses will not
become more used in the future, but future browsers will. That makes
forward compatability more important than backwards compatability.
Detecting specific versions of known browsers will necessarily not
work for future versions.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
McKirahan wrote:

<script type="text/javascript">
var adBtype = "??";
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
} else if (document.all) {
adBtype = "IE4";
} else if (document.layer s) {
adBtype = "NS4";
}
alert(adBtype);
}
</script>


There's no escape for the function:
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";retu rn;
}
if (document.getEl ementById && document.all) {
adBtype = "IE5+";retu rn;
}
if (document.all) {
adBtype = "IE4";retur n;
}
if (document.layer s) {
adBtype = "NS4";retur n;
}
adBtype= "unknown to this programmer";
}
Mick
Jul 20 '05 #4
"Mick White" <mw******@BOGUS rochester.rr.co m> wrote in message
news:0F******** ***********@twi ster.nyroc.rr.c om...
McKirahan wrote:

<script type="text/javascript">
var adBtype = "??";
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
} else if (document.all) {
adBtype = "IE4";
} else if (document.layer s) {
adBtype = "NS4";
}
alert(adBtype);
}
</script>


There's no escape for the function:
function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";retu rn;
}
if (document.getEl ementById && document.all) {
adBtype = "IE5+";retu rn;
}
if (document.all) {
adBtype = "IE4";retur n;
}
if (document.layer s) {
adBtype = "NS4";retur n;
}
adBtype= "unknown to this programmer";
}
Mick


Actually I modified one I found; it actually was:

function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
return;
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
return;
} else if (document.all) {
adBtype = "IE4";
return;
} else if (document.layer s) {
adBtype = "NS4";
return;
}
}
Jul 20 '05 #5
In article <Jm9%b.56686$Xp .269424@attbi_s 54>, Ne**@McKirahan. com
enlightened us with...
Is this a very good browser check?


No, but it's a great way of doing object detection. :)

There is NO good browser check. There are simply too many browsers.

--
--
~kaeli~
I do whatever my Rice Krispies tell me to.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6
McKirahan wrote:


Actually I modified one I found; it actually was:

function wB() {
if (document.getEl ementById && !document.all) {
adBtype = "NS6+";
return;
} else if (document.getEl ementById && document.all) {
adBtype = "IE5+";
return;
} else if (document.all) {
adBtype = "IE4";
return;
} else if (document.layer s) {
adBtype = "NS4";
return;
}
}


What if all the Booleans are false? You need to declare a global variable:
var adBtype="Unknow n" // A suggestion.
But read the other comments, there are probably hundreds of different
browsers out there, some of which obfuscate their headers. IOW your
"adBtype" is just a guess.
Mick
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2454
by: Dr. StrangeDub | last post by:
I am part of a group that has developed an ASP.Net web application. I am looking for a way to determine whether or not the browser is actually running on the web server. For this case (when executing IE on the webserver) I want to remove a link to Remote Desktop -- as the desktop is NOT remote in this case, and I believe doesn't work...
11
2167
by: James | last post by:
I wasn't sure where to post this so I'm sorry if this is the wrong place. But I would like to know what some of the differences are between client-side and server-side browser sniffing. I'm aware the client-side stops certain errors being transmitted so saves on bandwidth and server-side my catch errors that are missed on the client-side. ...
12
10145
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a...
5
3165
by: David Baker | last post by:
Hi all I am very new to ASP.Net. I am trying to create a sniffer for our program. We want our users to click our sniffer and hopefully the sniffer will check their computer against our requirements. I would like to ask experts like you to see which items are actually doable with ASP.Net. Below I listed all of the items we are looking for but I...
2
8072
by: Craig G | last post by:
is there a way to distinguish whether a client is using IE or Netscape? is there some sorta check i can run on the Page_Load event? or where would be the best place to do this? Cheers, Craig
4
2711
by: Paul W | last post by:
Hi - can someone point me to info on the issues/resolutions of supporting the safari browser? To help me understand, if I was developing pages in say FrontPage, what attributes would I set for 'target browser'? I'm having a helluva time with table layouts etc and goin' stir crazy.. Thanks, Paul.
22
2281
by: petermichaux | last post by:
Hi, I would like to display a message to Internet Explorer clients to encorage them to get Firefox. Yes they may like Internet Explorer but it is my site :) http://www.explorerdestroyer.com/ uses navigator.userAgent If ((ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) &&
6
2389
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am thinking about doing this since I got several cases that some of our internal users open more than one browser at the same time from our server. When one of the transactions was not completed finished, the second browser jusk pick up some session variables from the first browser and process right after that. It messed up...
3
7776
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
10
3248
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations where you could improve the application by detecting the browser vendor/version. Some of the posters here disagreed. Since then, I've had to deal with...
0
7836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.