Welcome to WebmasterWorld Guest from 54.210.61.41

Forum Moderators: open

Message Too Old, No Replies

Detect Gecko Version (like 1.7 or 1.8, not build number)

     
12:48 am on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


I'm trying to detect various builds of Gecko based browsers. I am not interested in the gecko build, I'm interested in the version. 1.7.11 is the latest stable build.

In Gecko UA's the Gecko version is found beore "rv:"...

Here is my guess (though there may be a better way of doing this)...

How would I be able to set "rv:" as a variable and then detect the charecters of X numbers ~or~ detect all characters BEFORE another variable character (such as a the closing parenthese)?

rv:1.8b4) Gecko/20050722 Firefox/1.0+

I would like to ultimately print out...

1.8b4

...with the given (part of) the above useragent.

9:17 am on Aug 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


str = "rv:1.8b4) Gecko\/20050722 Firefox\/1.0+" // fw slashes escaped for demo

/***
/^rv\:¦\).*$/g

- Every thing upto 'rv:', and longest substring starting with ')'
***/

alert(
str.replace( /^rv\:¦\).*$/g, '' )
)

! Replace currupted ¦ characters!

8:52 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Oh I should have put the whole useragent string IoI...

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8b4) Gecko/20050722 Firefox/1.0+

I'm still playing with it but what we've achieved so far is removing the stuff from ) on after the gecko version.

<script type="text/javascript">
var str = navigator.userAgent;

/***
/^rv\:¦\).*$/g

- Every thing upto 'rv:', and longest substring starting with ')'
***/

document.writeln(
str.replace( /^rv\:¦\).*$/g, '' )
)

! Re

if ($str = 1.7) {document.writeln('1.7')}

else if ($str = 1.8) {document.writeln('1.8')}
;
document.writeln(navigator.str);
</script>

9:26 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Let me guess how this works....

1.) /^ selects rv as the begining of the string?

2.) \ escapes :?

3.) \ escapes )

4.) .* is everything AFTER )?

We'll need to set clarify two variables (for me to understand this instead of just copy paste...

I know we need to set the useragent as a varable...

var = $ua

and then the version this script spits out...

var = $version

I'm not sure what this means (as I'm stuck having to go out for my retard school right now)...

/***
/^rv\:\).*$/g

I do at least know that...
'' )

the blank space between the two single quotes replaces the captured text with nothing.

10:21 pm on Aug 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


1 - 4 is pretty much as you say. There are 2 parts to the reg expression, separated by the ¦ 'or'.

The 1st part matches the 'rv:' at the beginning.
The 2nd part matches the first ) and everything following until the end ($).

I'm not sure what you're getting at after that. You seem to be referencing a variable, $str, and a property, navigator.str - neither of these yet exist.

You could just set:


var navVer = navigator.useragent.replace( /^rv\:\).*$/g, '' );

..but that's without having checked to see whether we're dealing with the intended browser, of course.

Else a little clarification needed.

10:42 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Well we still need to remove

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:

Also I'm trying to understand this as handling variables because I can understand how to effect variables more effectively versus your code (no offense) does not have structure that I understand overall (except pieces here and there).

We start with the useragent and I'm not sure how we're giving the useragent to this part (function?) of the script.

Then I want to assign "1.8b4" as a variable called "version" which I think you were able to do.

So yeah I don't understand how you captured the useragent and were able to start disecting it...or maybe I'm not looking at the script correctly?


var navVer = navigator.useragent.replace( /^rv\:?\).*$/g, '' );

document.write(navVer);

That should work but your syntax may be off? I'm still a little fuzy ;-)

Made a test script to ensure I was printing the variable out correctly...

<script>
var bob = '46';
document.write(bob);
</script>
11:06 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


I've had a little time to try a better guess though I know (since it's not working) that I'm off...


document.writeln(
str.replace(/^Mozilla¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' )
)
11:33 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Ok here is my static success...but I know the string will always be different (and I'll need your help with that please IoI)...


var str = navigator.userAgent;

/***
/^rv\:¦\).*$/g

document.writeln(
str.replace(/^Mozilla\/5.0 \(Windows; U; Windows NT 5.1; en-US; rv:¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' )
)

! Re

11:50 pm on Aug 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


I was having a look whil you posted your last. (¦¦ doesn't mean 'or' in an RE, btw)

I'm OK with string handling, but I'm not 100% familiar with UA strings, so I had to actually test this with a browser (!).

Again, 2 parts to the RE:

1) ^.*rv\:
beginning -> 'rv:'

2) \).*$
')' -> end
This is OK as long as no ')' appears before the 'rv:' (It doesn't look like one will)

Then paired up with an ¦ - 'or',
and given a 'g' modifier.

if( /Gecko/.test( navigator.userAgent) )
{
var version = navigator.userAgent.replace(/^.*rv\:¦\).*$/g,'');
alert(version);
}
else
alert('not Gecko');


In my Firefox, this gives me the string, 1.7.5

11:52 pm on Aug 4, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


WOOOOOOO! I think I've got it!

<script type="text/javascript">
<!--
var str = navigator.userAgent;

/***
/^rv\:¦\).*$/g
***/

document.writeln(
str.replace(/^Mozilla.*rv:¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' )
)
//-->
</script>

What do you think?

11:58 pm on Aug 4, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


Looks like there's something wrong with the JS syntax there:

str.replace(expr, '' ) ( expr, '' );

That may be legal, but anything after the ¦¦ will be ignored (unless the fn returns '')

12:03 am on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


..so it does work (I tested it). - It comes after a while (then it goes again).

The 'Mozilla' is redundant though, as is the bit after ,
which leaves us with my one a couple of posts back.

PS

Are you concerned about the XHTML strict / document.write issue?

12:31 am on Aug 5, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


I'm using XHTML 1.1 (and as far as I know there is no transitional/strict with 1.1?)

Regardless what is the issue you're speaking of? I'm definitly interested...

Also, I'm going to do conditionals in regards to detect if the string = 1.7 / 1.8, etc. I was having trouble detecting and duplicating this independent of the string...

if ($str = 1.7) {document.writeln('1.7')}
else if ($str = 1.8) {document.writeln('1.8')}

The basic idea is that it should print 1.8 but it's printing out 1.7 like it is right now.

1:01 am on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


I'm not certain how the build numbers progress.
Mine is "1.7.5", and thus does not equal 1.7 or 1.8

(Remember that you are comparing a string with a number. Having said that, "1.8" == 1.8 in Javascript)

Could do something like this:


version = version.substring(3);
if (version = "1.7") {document.writeln('1.7')}
else if (version = "1.8") {document.writeln('1.8')}

..but then, is there any reason not to write:


document.writeln(version.substring(3))

?

1:23 am on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


This basic gist of the document.write thing goes like this (er.. I think)

XHTML 1.1 shouldn't be served as text/html.

[google.se...]
[w3.org...]

At some point when evrything is sorted out, and you serve the document with a recognised XHTML media type
then you'll have to change the script because 'proper' browsers have deactivated any script
functions that could potentially insert malformed markup. So

XXX document.write
XXX innerHTML (when used as a setter)

The solution is to use the DOM instead.

6:36 am on Aug 5, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Well here is how I'm attempting to put it together...

I'm setting the results of the $str variable to be set to the value of the $gecko variable. That way we can be clear on before and after (I can get confused easily hehe)...

<script type="text/javascript">
<!--
var str = navigator.userAgent;

/***
/^rv\:¦\).*$/g
***/

var gecko = str.replace(/^Mozilla.*rv:¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' );

version = gecko.substring(3);
if (version = "1.7") {document.writeln('1.7')}
else if (version = "1.8") {document.writeln('1.8')}
document.writeln(version.substring(3))

//-->
</script>

Gecko builds numbers are as so...
1.7, 1.7.1-1.7.9, 1.7.10, 1.7.11.

There is the Firefox roadmap...
[mozilla.org...]

Originally 1.8 was supposed to be part of Firefox 1.1. 1.9 to be part of Firefox 1.5, and 2.0 Gecko core to be part of Firefox 2.0.

They goofed and instead of closing the core and finishing up 1.8 they messed around and added features and then figured they could not call it 1.1 anymore. Now they're calling it 1.5 (when it goes stable) and they are going to have to pick something like 1.6-1.9 before the 2.0 release of Firefox if they want to align the Firefox and Gecko version numbers.

Gecko 1.8 fixes all but one currently known Gecko bugs that you'll find on my site, the most famous being the inability to use your scroll wheel with my overflow div (id=body). The one known bug that is not fixed (and don't think will be fixed for 1.8) is autoscroll (typically what the scrollbutton is set to when nothing else has been set or you have no ability to set it because there is no extra software installed on XP to give you those options).

They've got 70 bugs left (had 71 as of last week) so progress is slow, but if you click on the bugs link it will show you what they have set to cut off a stable release.

Rc (Release Canidates) will follow the current betas. 1.1 was originally aimed for a March 2005 release so I've been using nightly builds to deal with the bugs at my end but there is little I can do without recoding my site at a more fundelmental point.

Right now I am creating a rendering core notification icon with a color coded border. The rendering icon will use Gecko, MSIE, and Opera icons (to start out at least) using various color codes per version of each rendering core. 1.8 will either have full green or a mixed green/yellow border. Clicking the icon will show you all known issues that afflict your browser. MSIE below 5.5 shares the same no-scrolling bug for overflow divs. With the new version of my site aimed to accomate accessibility standards however only MSIE 7 will be able to get away with a possible yellow code (orange is a high warning). Apache is/will be used for red coded agents that have severe issues with the site. For example Netscape 4X will crash when it loads my site...except that I just tested it and it does not load HTML elements via Javascript from the head of a document. Opera 6 fails to do so as well and thus does not work with the styleswitcher I've personally put together (proud of that one hehe). Netscape 4 is a no go around... but Opera 6 can be dealt with serverside...

It's certainly a challenge, but I wouldn't be working on my 27th version of my site if I gave up easily now would I?

I could add this to the header info ... whats the link to the WW header check tool? I don't remember where someone posted that and none of the links I check hunt me to it's whereabouts.

I don't percieve an error and have not seen anything render for any ridculousily unknown reason...don't get me wrong, if I'm incorrectly serving XHTML pages as HTML I'd like to fix it, but it seems there are more issues AFTER I fix it as there seem to be none now? Could you simplify it a bit?

7:40 am on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


John, the code you posted (in the block) seems to have a bit of everything, and includes the section after the which does nothing - so I'm not sure what's going on there.

A combination of the code in #9 and #14 will do the thing.

Could you simplify it a bit?

What's that?

I'm not necessarily suggesting you actually need to change anything right now, WRT document.write. It's just that if/when you do serve the document with a media type like "application/xhtml-xml" (as one apparently should), then browsers like Firefox will no longer execute document.write. Advance warning.

8:02 pm on Aug 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


[b]ouch![b] What was I thinking of?

To get the first 3 characters:

substring(0,3) // not substring(3)

(sorry)

10:37 pm on Aug 5, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


No problem...

This rocks...just one small problem left...

I'm using Gecko 1.8 but it is printing out 1.6 code. Somehow the last if arguement blindly accepts whatever first condition is set to as true. Is there something I'm missing? Typically this is something I wouldn't have problems with? IoI...

<script type="text/javascript">
<!--
var str = navigator.userAgent;

/***
/^rv\:\).*$/g
***/

var gecko = str.replace(/^Mozilla.*rv:\).*$/g, '' ) ( /^rv\:\).*$/g, '' );

document.writeln('Gecko full version is');
document.writeln(gecko);

var version = gecko.substring(0,3);
document.writeln('<br />');
document.writeln('<br />');
document.writeln('Gecko general version is');
document.writeln(version);

document.writeln('<br />');
document.writeln('<br />');

if (version = 1.6) {document.writeln('<br />1.6 html code')}
else if (version = 1.7) {document.writeln('<br />1.7 html code')}
else if (version = 1.8) {document.writeln('<br />1.8 html code')};
//-->
</script>

ALSO...substring(0,3);...

Does 0 mean start with the first character and end with the third? That would be four characters though?

10:25 am on Aug 6, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


Does 0 mean start with the first character and end with the third?

No. Starts at 0. Ends before 3. This kind of non-inclusive upper bound is often used.

Somehow the last if arguement blindly accepts whatever first condition is set to as true.

That's because it technically is true. You've made a little slip.
It should be.

if (version == 1.6)

Meanwhile. This should do it all...

var gecko = navigator.userAgent.replace(/^.*rv\:¦\).*$/g,'');
var version = gecko.substring(0,3);

document.writeln(
'Gecko full version is ' +gecko +'<br /><br />'
+ 'Gecko general version is ' +version+'<br /><br /><br />'
+ version + ' html code'
);

5:40 am on Aug 17, 2005 (gmt 0)

New User

10+ Year Member

joined:June 28, 2005
posts:11
votes: 0


i wrote this function to detect the browser version and name

i hope it helps :D

you can email me guys at robert@activediscovery.net

function detectBrowser(){
var browserInfo=new Object;
var useragent = navigator.userAgent;
var Browser = (useragent.indexOf('Opera') > -1)? 'Opera' : navigator.appName;
var pos = useragent.indexOf('MSIE');

if (pos > -1) {
Version = useragent.substring(pos + 5);
var pos = Version.indexOf(';');
var Version = Version.substring(0,pos);
}
if (Browser == "Netscape") {
var Version = useragent.substring(8);
var pos = Version.indexOf(' ');
var Version = Version.substring(0, pos);
}
var pos = useragent.indexOf('Opera');
if (pos > -1) {
Version = useragent.substring(pos + 6);
var pos = Version.indexOf(' ');
var Version = Version.substring(0, pos);
}

if (Browser == "Netscape" && parseInt(navigator.appVersion) >= 5) {
var pos = useragent.lastIndexOf('/');
var Version = useragent.substring(pos + 1);
}

browserInfo.version=Version;
browserInfo.name=Browser;

return browserInfo;

}

2:43 pm on Aug 17, 2005 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3178
votes: 22


Ok this is what we now and it ALL works! I put semi-colons at the ends of my if statements for the JAB way of detecting the versions (if 1.9 then do this (doc write)). A huge thanks for all your awesome help!

Going to have to email Knives, his code is not working? Looks interesting though.

<script type="text/javascript">
<!--
var str = navigator.userAgent;

/***
/^rv\:¦\).*$/g
***/

var gecko = str.replace(/^Mozilla.*rv:¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' );

document.writeln('Gecko full version is');
document.writeln(gecko);

var version = gecko.substring(0,3);
document.writeln(
'Gecko full version is ' +gecko +'<br /><br />'
+ 'Gecko general version is ' +version+'<br /><br /><br />'
+ version + ' html code via Bern');

if (version == 1.6) {document.writeln('<br />1.6 html code via JAB')}
else if (version == 1.7) {document.writeln('<br />1.7 html code via JAB')}
else if (version == 1.8) {document.writeln('<br />1.8 html code via JAB')}
else if (version == 1.9) {document.writeln('<br />1.9 html code via JAB')}
else {document.writeln('<br />Unknown Gecko code')};

//-->
</script>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members