Forum Moderators: open
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.
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>
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.
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.
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>
var str = navigator.userAgent;/***
/^rv\:¦\).*$/gdocument.writeln(
str.replace(/^Mozilla\/5.0 \(Windows; U; Windows NT 5.1; en-US; rv:¦\).*$/g, '' ) ¦¦ ( /^rv\:¦\).*$/g, '' )
)! Re
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
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.
(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')}
document.writeln(version.substring(3)) ?
XHTML 1.1 shouldn't be served as text/html.
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.
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?
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.
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?
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'
);
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;
}
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>