amit wrote:
Quote:
Randy Webb wrote:
Quote:
amit said the following on 7/27/2006 5:35 PM:
Quote:
Hello group,
>
I'm kinda skeptical about a code is being used in my js program. All it
does is checking what browser is being run and finds out if FLASH is
installed or not.
It does the first unreliably and doesn't do the second at all. Please
read about browser detection, it is utterly unreliable.
[...]
Quote:
>
IEFlashStat = ((navigator.appName.indexOf("Microsoft") != -1) &&
(navigator.appVersion.indexOf("Windows") !=
-1))&&
(parseFloat(navigator.appVersion) >= 4 ) ? true
: false;
Your test is equivalent to:
IEFlashStat = (true)? true : false;
Consider:
IEFlashStat = navigator.appName.indexOf("Microsoft") != -1
&& navigator.appVersion.indexOf("Windows") != -1
&& parseFloat(navigator.appVersion) >= 4;
Quote:
if (IEFlashStat )
{
alert("IE and flash OK");
//Ok, the browser detected as IE4 or 4+; ready for
Flash events
_bFlash = true;
If the tests above returned true, how does that prove that the browser
is IE? Or that Flash is installed? And why not set _bFlash in the
first place, why store the result in IEFlashStat then copy it to
_bFlash?
Quote:
}
else
{
//The browser is not IE so check if we are dealing with
NN or FF
NNFlashStat = ((navigator.appName == "Netscapt") &&
(navigator.userAgent.indexOf("Mozilla") != -1))
? ture : false;
Supposing you fix the "Netscapt" typo, the value of NNFlashStat will be
"ture".
Which neatly type-converts here to boolean true. Compensating errors -
clever! If you ditch the unnecessary test to see if true is true, you
remove the possiblity of making that typo altogether.
Quote:
{
alert("yep, Flash in FF or NN");
_bFlash = true;
So how did that prove that Flash was installed? Even if it detected
Flash reliably (and it absolutely doesn't), how do you know the user
isn't blocking Flash content? e.g. using Firefox and Flashblock.
The bottom line is, your "detection" is useless. Assume that some of
your visitors can't see your Flash stuff and that you have no way of
knowing which ones they are.
[...]
Quote:
one more thing when I use macros or predefined variable in Javascript
it has difficulty why is that?
>
let's say at the top of the code I have:
>
var ms = "Microsoft";
navigator.appName.indexOf(ms)
>
will not work. why?
What is your definition of 'work'?
You have initialised a global variable with a value of the string
"Microsoft". You then test to see whether that string exists within
the string returned by navigator.appName. You don't do anything with
the result, it vanishes into the ether - unused, unloved and
unlamented.
--
Rob