04.11.2015 Views

javascript

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Client Detection<br />

With the release of Opera 8, the language part of the user - agent string was moved inside of the<br />

parentheses to better match other browsers, as follows:<br />

Opera/ Version ( OS-or-CPU ; Encryption ; Language )<br />

Opera 8 on Windows XP yields the following user - agent string:<br />

Opera/8.0 (Windows NT 5.1; U; en)<br />

By default, Opera returns a user - agent string in this simple format. Currently it is the only one of the<br />

four major browsers to use the product name and version to fully and completely identify itself. As with<br />

other browsers, however, Opera found problems with using its own user - agent string. Even though it ’ s<br />

technically correct, there is a lot of browser - sniffing code on the Internet that is geared toward user - agent<br />

strings reporting the Mozilla product name. There is also a fair amount of code looking specifically for IE<br />

or Gecko. Instead of confusing sniffers by changing its own user - agent string, Opera identifies itself as a<br />

different browser completely by changing its own user - agent string.<br />

As of Opera 9, there are two ways to change the user - agent string. One way is to identify it as another<br />

browser, either Firefox or IE. When using this option, the user - agent string changes to look just like the<br />

corresponding one for Firefox or IE, with the addition of the string ” Opera ” and Opera ’ s version<br />

number at the end. Here ’ s an example:<br />

Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50<br />

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.50<br />

The first string identifies Opera 9.5 as Firefox 2 while maintaining the Opera version information. The<br />

second string identifies Opera 9.5 as Internet Explorer 6 and includes the Opera version information.<br />

Although these user - agent strings pass most tests for Firefox and IE, the possibility of identifying Opera<br />

is open.<br />

Another option for identifying the browser is to mask it as either Firefox or IE. When masking<br />

the browser ’ s identity, the user - agent strings are exactly the same as would be returned from the<br />

other browsers — the string ” Opera ” does not appear, nor does any Opera version information. There is<br />

literally no way to distinguish Opera from the other browsers when identity masking is used. Further<br />

complicating the issue is Opera ’ s tendency to set site - specific user - agent strings without notifying the<br />

user. For instance, navigating to the My Yahoo! site ( http://my.yahoo.com ) automatically causes<br />

Opera to mask itself as Firefox. This makes identifying Opera by user - agent string very difficult.<br />

Before version 7, Opera could interpret the meaning of Windows operating - system<br />

strings. For example, Windows NT 5.1 actually means Windows XP, so in Opera 6,<br />

the user - agent string included Windows XP instead of Windows NT 5.1. In an effort<br />

to be more compatible with other browsers, version 7 started including the officially<br />

reported operating - system version instead of an interpreted one.<br />

239

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!