fooling safari with javascript

L

laredotornado

Hi,
Is it possible to fool Javascript running on a Mac Safari web
browser into believing it is a PC IE browser? We have the following JS
code that is detecting both Mac and Safari. Sadly, we do not have
control over the code.

// Global variables for platform branching
var NN, IE, MAC, browserVersion



// Flag to ensure that projectData document is loaded
var framesLoaded = false;

// Browser test
if (parseInt(navigator.appVersion) >= 4)
{
if (navigator.appName == "Netscape")
NN = true
else
IE = true
}
else
{
// browser is to old
alert("This page will not function properly in this browser because it
requires a browser version of 4.0 or above.");
}


// Version
if (IE) {
browserVersion =
navigator.appVersion.charAt(navigator.appVersion.indexOf("MSIE") + 5);
}
else if (NN) {
browserVersion = parseInt(navigator.appVersion);
}

// Computer test
if (navigator.appVersion.indexOf("Mac") != -1) {
MAC = true;
}

if (NN && MAC) {
alert("This activity cannot be used on a Macintosh running a Netscape
Web browser.");
back();
}



Thanks, - Dave
 
R

Randy Webb

(e-mail address removed) said the following on 10/4/2005 5:00 PM:
Hi,
Is it possible to fool Javascript running on a Mac Safari web
browser into believing it is a PC IE browser? We have the following JS
code that is detecting both Mac and Safari. Sadly, we do not have
control over the code.

Then you need to fire whoever is in control of that crappy worthless code.
 
R

RobG

Hi,
Is it possible to fool Javascript running on a Mac Safari web
browser into believing it is a PC IE browser?

'JavaScript' has no concept of what a Mac running Safari is. JavaScript
and certain DOM features can be used to write a program that asks for
certain information from a browser. The browser will provide whatever
information it has been told to provide.

In the case of Safari, depending on which version, the user can elect to
have the browser masquerade as any number of browsers running on a
variety of operating systems.

Safari is certainly not alone in this respect.
We have the following JS
code that is detecting both Mac and Safari. Sadly, we do not have
control over the code.

Which I understand to mean:

"The author/vendor of this code has told us it not let anyone using
Safari running on Mac OS access the site."

So your question becomes:

"Will it work as specified?"

Without understanding why Safari users should be singled out for such
treatment, or why the programmer decided to specifically exclude certain
browsers from using the application, the answer is 'sometimes'.

The question you need to ask is:

"Why?"

Do you refuse to deal with left-handed people? Or those who refuse to
wear shoes with laces? Or those with spectacles? Excluding users based
solely on their choice of browsing platform makes about as much sense as
discriminating on any of the above factors.

The only reason to attempt browser detection and subsequently debar
certain users from site access is because of programmer incompetence.

[... rather worthless browser sniffing code removed ...]

Sorry to be harsh, but browser sniffing is bad and has been recognised
as 'worst practice' for many, many years.

Browser detection, of itself, is quite harmless. It becomes an issue
when it is used as above, that is, to prevent users accessing a site
based solely on their choice of browser. It is sure sign of lazy or
incompetent programming.

Despite the above, it still has supporters who refuse to be brought into
the 21st century. Here is a reasonably balanced article:

<URL:http://webdesign.about.com/library/weekly/aa120902a.htm>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top