Randy Webb skrev:
> marss said the following on 12/19/2006 5:15 AM:
>> Randy Webb wrote:
>>> marss said the following on 12/19/2006 5:05 AM:
>>>> Pugi! wrote:
>>>>
>>>>> }
>>>>> if (document.all) { // here I should test for IE, but also
>>>>> Opera gets
>>>>> caught
>>>>> return [x,curtop];
>>>>> } else {
>>>>> return [curleft,curtop];
>>>>> }
>>>>> }
>>>>>
>>>> if (document.all && user_agent.indexOf("opera") == -1)
>>>> {
>>>> //IE
>>> No, it is a browser that supports document.all and doesn't have opera in
>>> the userAgent string. It does *NOT* mean it is IE.
>>>
>>
>> This is advice on specific case. Simplified for clarity.
>
> It is still useless advice that teaches people to think the
> navigator.userAgent string can be used to identify a browser when it
> can't. Want a test that will, without a doubt, identify Opera?
>
> if (window.opera){alert('YOU ARE USING OPERA!!!')
>
> Anything else with regards to the user agent string identify the browser
> is unmitigated garbage.
>
Hi Randy.
Sorry, but your code will not work and is just garbage.
Quote from
http://www.javascriptmall.com/learn/lesson5.htm:
"You use the if statement in JavaScript to make decisions. The syntax
for it is as follows:
if (condition){
statements
}
The if keyword identifies this as an if statement. The condition in the
parenthesis ( ) is evaluated to determine if true, and if so then the
statements inside the curly braces { } are executed, otherwise they are
skipped and the programs continues with the first line after the if
statement."
In other words, you can write one of the following:
simplest:
if (window.opera) alert('YOU ARE USING OPERA!!!');
....or a more correct and even working use of curly braces:
if (window.opera){alert('YOU ARE USING OPERA!!!');}
....or the above in a bit more easy to read way:
if (window.opera) {
alert('YOU ARE USING OPERA!!!');
}
I hope this helps you a bit. Javascript is not always easy to learn for
the beginner but I'm sure you'll soon get the hang of it.
Have a nice day. Be nice to people and they will be nice back making
your entire day nice.
/MB