Forum Moderators: open

Message Too Old, No Replies

But MOM, I want Browser Validation!

The more I learn the less I understand

         

OhMyPixel

9:51 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



OK, I wrote a simple javascript to detect browser versions and print the results to the screen. On my 2000 machine these are the results I get for the respective browsers

(these results look normal)
Netscape 4.75 :
You are using Netscape version 4.75 [en] (Windows NT 5.0; U)

(this is returning version 4.0 because i'm using the parseFloat command, right?)
MSIE 6.0 : You are using Microsoft Internet Explorer version 4.0 (compatible; MSIE 6.0; Windows NT 5.0)

(I could live with Mozilla being detected as netscape)
Mozilla 1.0 : You are using Netscape version 5.0 (Windows; en-US)

(what the heck is opera being detected as MSIE for?)
Opera 6.03 : You are using Microsoft Internet Explorer version 4.0 (compatible; MSIE 5.0; Windows 2000)
----------------
<script language="JavaScript">
<!-- Hide From Old Browsers
var browser_name = navigator.appName;
var browser_version = navigator.appVersion;
document.write ( "You are using " + browser_name + " version " + browser_version );
//-->
</script>
-----------------

So how can someone do a working browser detect based on the results of this? Any insight. I tried a forum search but the link was broken!

Thanks,

-OMP

dcheney

10:01 pm on Jun 18, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Opera has an easy and effective way for the user to appear either as Opera, or as: MSIE 5.0; Mozilla 3.0, 4.78, or 5.0

mavherick

10:07 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



You see the thing is with Opera, you can manually set the user agent to be IE or other browser as well.

Now I don't think there is a way to know if somebody is using Opera pretending to be IE, but I could be wrong. In fact, I would be really nice if there was a way to detect this...

toadhall

10:36 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



Opera shows up in the string returned from the HTTP_USER_AGENT environment variable regardless.

Mozilla/3.0 (Windows 98; U) Opera 6.0 [en]
Mozilla/4.76 (Windows 98; U) Opera 6.0 [en]
Mozilla/5.0 (Windows 98; U) Opera 6.0 [en]
Mozilla/4.0 (compatible; MSIE 5.0; Windows 98) Opera 6.0 [en]
Opera/6.0 (Windows 98; U) [en]

So, you can search the string for "Opera".

I use something like this in php:

<?
$UA = getenv(HTTP_USER_AGENT);
if (strstr($UA,"Opera")) {
echo ("You're using Opera.");
}
?>

Of course this is server-side scripting.

OhMyPixel

10:42 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



So, is there anyway to setup a working browser detect script with JavaScript? It seems like there is no way to detect the browser via client-side?

toadhall

10:58 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



Check [url=news://news.opera.no/opera.tech/18933]this[/url] out.

toadhall

11:01 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



I'm sorry, o-m-pix; that link worked a second ago. D'oh.
This is essentially what was said:

All opera user-agent strings do contain the word 'Opera', so just search for that.
In Javascript,

this.ua = navigator.userAgent.toLowerCase();
this.opera = this.ua.indexOf('opera') != -1;

Recent versions also report true for "if(windows.opera)". This also
applies to Opera 5, so you'd have to check version number also.

news://news.opera.no/opera.tech/18933

mdharrold

11:07 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



Handy Generic Javascript [webmasterworld.com] message #18 has a browser sniffer that detects Opera spoofing.

toadhall

11:23 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



<script language="JavaScript">
<!--
this.ua = navigator.userAgent.toLowerCase();
this.opera = this.ua.indexOf('opera') != -1;
if(this.opera) {
document.write("Yup, it's Opera all right!");
} else {
document.write("Sorry, not Opera.");
}
//-->
</script>

...for short. ;)

OhMyPixel

11:34 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



toadie,

thanks. that'll work for opera but I'm looking for a redirect script that works for ALL browsers. I need something that can distinguish opera from IE from NE, etc. Keep in mind I'm doing this all client-side.

im gonna check out the link as well and do some reading.

-OMP

toadhall

11:42 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



Then by all means use the script recommended by mdharrold above. It will detect Opera, IE, HotJava, AOL, WebTV, Gecko, NN, ...

OhMyPixel

11:52 pm on Jun 18, 2002 (gmt 0)

10+ Year Member



toad,

thanks again, I'm going to fiddle around with the script and see what I can do with it. I don't think I mentioned this but I'm in the middle of teaching myself JavaScript.

-OMP

starway

9:41 am on Jun 21, 2002 (gmt 0)

10+ Year Member



In case of Opera, there's a way to know for sure that you deal with it.
You have to use navigator.userAgent property and search for "Opera" substring in it. It is always present there regardless user-defined identification.

There's also another way to do it. Check this:
window.opera
It is undocumented Opera's window property.

var opera = (window.opera ? true : false)
This will be true only in case of Opera browser.

good luck