Jump to content

Extracting Part Of A String


RenegadeFX
 Share

Recommended Posts

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

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

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

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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...