By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

fooling safari with javascript

P: n/a
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.i ndexOf("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

Oct 4 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
la***********@zipmail.com 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 4 '05 #2

P: n/a
la***********@zipmail.com wrote:
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>

--
Rob
Oct 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.