JavaScript | PHP: Hypertext Preprocessor | SSI: Server-side includes |
Some Web sites are designed to work correctly only with certain browsers, and some sites will not even let you access them unless you are using one of their approved browsers. All browsers provide information about their identity that can be queried by Web sites and computer programs, but it is not normally visible.
This Web page checks that you are using a Safari browser, makes the information about its identity visible, attempts to determine whether it is spoofing, and attempts to display its version number.
If your browser could not be identified, or if it was identified incorrectly, then please send me a message so that I can try to improve the identification.
Some Web browsers can be configured to supply identification that belongs to other browsers, a process known as spoofing. This can allow browsers to access Web sites that attempt to restrict access to specified browsers. Perfect spoofing would be impossible to detect.
Safari always identifies its vendor as Apple, and this always allows it to be detected when it pretends to be Internet Explorer or other browsers, but not when it pretends to be other versions of Safari.
To set up spoofing, the Develop menu needs to be made visible:
Then choose a User Agent:
There are several ways of identifying a browser, but this page uses some fairly simple JavaScript that someone without programming experience can understand and modify.
The first step is to make sure that you are using a Safari browser, by checking for the presence of the string “apple” in the vendor property of the JavaScript navigator object. If this is not found, then a message and a link to the main browser identification page will be displayed.
if (navigator.vendor.toLowerCase().indexOf("apple") == -1)
{
document.write("<p><strong>You do not appear to be using a Safari Web browser.<\/strong><\/p>");
}
The second step is to retrieve the userAgent data that your Safari browser supplies as part of the JavaScript navigator object, for example:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12
The third step is to convert the data to lower case and search it for one or more strings of characters whose presence and/or absence (alone or in combination) can be used to detect spoofing and to identify a browser. For example, the following definition specifies the presence of “firefox/2”.
else if (navigator.userAgent.toLowerCase().indexOf("firefox/2") != -1)
This indicates that your Safari browser is configured to spoof as Firefox 2, and so when a match is found, this causes the next piece of JavaScript to write some HTML that displays a message as part of the Web page:
document.write("<p><strong>Your Web browser claims to be Firefox version 2, but appears to be Safari providing a false identity.<\/strong><\/p>");
The fourth step is to check for a string that indicates the browser version, for example:
else if (navigator.userAgent.toLowerCase().indexOf("version/3.1") != -1)
Finding a match causes the next piece of JavaScript to write some HTML that displays a message about the version as part of the Web page:
document.write("<p><strong>Your version of Safari appears to be 3.1<\/strong><\/p>");
This type of identification is not completely accurate, especially when browsers pretend to be other browsers, but it works most of the time.
Send comments or questions to Alan Wood
Created 20th December 2001 — Updated 17th November 2019
Copyright © 2001–2019 Alan Wood