1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

User Agents

Join the Discussion

Questions? Comments?

Some antiquated scripts use browser sensing to try to determine which browsers support certain code and which don't. This dates bback to the days of Internet Explorer 4, Netscape 4, and earlier versions of those browsers where there were only the two browsers that supported the fancier JavaScripts and they did it in different ways.

These days all modern browsers support most JavaScript code and it is those antique web browsers that do not do things the standard way that all more recent browsers use. Feature sensing rather than browser sensing is the modern way of determining which browsers support what as otherwise you would be amending your script every day to add new browser versions that now support additional features.

There is another disadvantage to using browser sensing. Because of those antiquated scripts, modern browsers often need to masquerade as one of those two antique browsers (usually IE) in order for web pages that use such obsolete code to work in modern browsers. This makes it extremely difficult to tell exactly which browser it really is because it has been configured to report itself as something else.

In fact while the majority of people do not change the configuration of their browser until they need to in order to get around such stupid code, there is no way to accurately identify what a browser really is as the useragent field that the browser information is stored in can be set to anything at all. Some browsers make this extremely easy to do while others make it harder.

The Opera web browser offers an option from the menu bar to set the useragent so that the browser can identify itself as Opera, Internet Explorer or Mozilla. Using this menu option the person using the browser can set the browser to identify itself as any of the three browsers on a page by page basis. What is more the browser also saves a file called ua.ini in the profile which contains a list of which useragents to use for specific sites so as to allow you to have the useragent change dynamically depending on which site you visit. Opera itself also updates this file regularly to add additional sites to the list where the browser will identify itself as a different browser in order for the site to work with their antiquated browser sensing script that is testing incorrectly. Opera is one of the more restrictive of the browsers when it comes to how it identifies itself as the useragents that it can use are built in and you can only choose between the predefined values.

Both Internet Explorer and Mozilla/Firefox allow you to set the useragent to anything at all. Firefox makes it easiest to do. To change the useragent in Firefox simply type about:config in the address bar and then right click in the window and select new. Now you just create a new configuration entry called general.useragent.override and set it to whatever value you like.

To change the useragent in Internet Explorer you need to edit the registry. This is done by selecting Run from the Start menu and typing regedit as the program to be run. The entry you are looking for is:

Current Version
Internet Settings

If an entry exists anywhere within this entry called User Agent then you can update that, otherwise you need to create that key. Internet Explorer breaks the useragent into six parts and so you need to set up each of the six parts separately. The four main parts are {default}, Compatible, Version, and Platform. If you omit any of these four then the browser will use the default value built into the browser for thhat part of the user agent. You can also set up additional keys within the User Agent key called Pre Platform and Post Platform and set token values there that will appear on either side of the platform variable.

Safari also allows you to set the user agent. To do so you need to have the Debug menu enabled which then provides you with an option for changing the user agent. Again as with Opera, the primary purpose of this is to allow the browser to be set to masquerade as IE or Firefox in order to bypass antiquated browser sensing scripts.

As you can see from this, there is no point whatsoever in trying to use browser sensing to decide what action to take within your script. Opera and Safari can easily identify themselves as IE or Firefox and IE or Firefox can easily identify themselves as anything at all.

Related Video
Compete's Stephen Dimarco on user-generated content

©2016 About.com. All rights reserved.