RenegadeFX Posted January 2, 2009 Share Posted January 2, 2009 ok so here's what I want to dosay I'm running Firefox Version 3.0.5 here's what the navigator.userAgent would look likeMozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.5) Gecko/2008120121 Firefox/3.0.5I just want to extract the Firefox/3.0.5 from that.any help would be appreciated Link to comment Share on other sites More sharing options...
zppblood Posted January 2, 2009 Share Posted January 2, 2009 You shouldn't want to do certain things that depend on certain browsers being used. They can easily be forged to make you think they are using one browser, but using another. The User-Agent string isn't going to look the same with different browsers, such as Internet Explorer being on the end instead of Firefox.Here is something about the User-Agent string with Internet Explorer from Microsoft.http://msdn.microsoft.com/en-us/library/ms537503.aspxAs you compare the two strings together for the two different browsers, you will see they don't look the same.You could also try navigator.appName instead, but it returns Netscape when I use Firefox. Link to comment Share on other sites More sharing options...
RenegadeFX Posted January 2, 2009 Author Share Posted January 2, 2009 Well I was thinking I could do something like this var AppName = navigator.appName;var Version = navigator.appVersion;var Cookies = navigator.cookieEnabled;var Platform = navigator.platform;var UserAgent = navigator.userAgent;if (AppName != "Microsoft Internet Explorer" && UserAgent.match("Firefox") != null) { alert("Your Using Firefox") }else if (AppName != "Microsoft Internet Explorer" && UserAgent.match("Safari") != null) { alert("Your using Safari"); }else { alert("Your using Microsoft Internet Explorer"); } Link to comment Share on other sites More sharing options...
zppblood Posted January 2, 2009 Share Posted January 2, 2009 There are a lot more browsers that are popular (Opera, Konqueror, Google Chrome). Link to comment Share on other sites More sharing options...
RenegadeFX Posted January 2, 2009 Author Share Posted January 2, 2009 well yeah I kinda figured that. do know of any good way of detecting the users Browser? Link to comment Share on other sites More sharing options...
zppblood Posted January 2, 2009 Share Posted January 2, 2009 I guess you can do what you were doing with getting the User-Agent string and searching through it with an array of popular browsers with JavaScript. You could use PHP (if your hosts allow it), where you can download a file that contains a bunch of user-agent strings and lists it properties (including browser), and uses PHP to grab that information from the file.http://us2.php.net/manual/en/function.get-browser.php Link to comment Share on other sites More sharing options...
rnd me Posted January 3, 2009 Share Posted January 3, 2009 if you don't know how to, you probably should not be trying to filter browsers.the only good reason to do so is to work around rendering/handling bugs in different browsers.object detection is a much more robust manner of safely handling different browser's capabilities.otherwise, you must for example, update your app every time opera adds new features that might be used by your code. Link to comment Share on other sites More sharing options...
jeffman Posted January 3, 2009 Share Posted January 3, 2009 An example of object detection: if (XMLHttpRequest) { return new XMLHttpRequest();} Since the thing we're after here is an XMLHttpRequest object, it's more logical to see if such an object can in fact be generated. The alternative would be to sniff for IE, which kind of works, but doesn't really tell us what we want to know. Link to comment Share on other sites More sharing options...
RenegadeFX Posted January 4, 2009 Author Share Posted January 4, 2009 Wow thanks that helped somewhat but What i'm really trying to do is detect the browsers width/Height so I can center an Absolutely positioned Object =D Link to comment Share on other sites More sharing options...
zppblood Posted January 4, 2009 Share Posted January 4, 2009 You can use the height/width properties for either the screen (browser window) or document (actual web page they are viewing).document.widthdocument.heightscreen.widthscreen.heightThough you probably should use CSS properties/values to center it instead of relying on JavaScript. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.