...

View Full Version : Please help: Can't get my get_os function to work..



ShadowIce
05-14-2009, 04:41 PM
Hi everybody. I've been doing some research on a function I've created using alot of data gathered from google. I need some help on the function b/c I have tried everything and to no avail. What I need help with is to be able to get the name AND version of ANY browser, reguardless of if it is a fake user agent or not. Like for example, if you wanna find out if someone is on Firefox, it would say: Mozilla Firefox x.x where x.x = version. It will be used in my security code for PHP that I made.

Do you see this line? "if (/navigator.userAgent (\d+\.\d+);/.test(navigator.userAgent)){ //test for ANY browser" ?

Well I need it to test for ANY browser, using useragent.

Heres the code:


<script>

/*This code is free for use as long as this header remains in contact

//Created by ShadowIce
//You may not change, steal, or delete this code without permission from the author
//Created on: Thursday, May 14th, 2009 | 10:32 AM

*/

function get_os(){

var ua = navigator.appName; //navigator.userAgent; //.toLowerCase();
var thebrowser = ua;
var browser = thebrowser;

var b_version=navigator.appVersion;
//var version=parseFloat(b_version);

//var ver = version;
var os = browser;

if (/navigator.userAgent (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
var version=new Number(RegExp.$1) // capture x.x portion and store as a number
//}else if(/Mozilla (\d+\.\d+);/.test(navigator.userAgent)){
// var version=new Number(RegExp.$1) // capture x.x portion and store as a number
}

browser = os+" "+version;

return browser;

}

document.write('You are on '+get_os());

</script>

Thanks! :)

~ShadowIce~



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum