Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > FAQ Topic - How do I detect Opera/Netscape/IE?

Reply
Thread Tools

FAQ Topic - How do I detect Opera/Netscape/IE?

 
 
FAQ server
Guest
Posts: n/a
 
      09-07-2006
-----------------------------------------------------------------------
FAQ Topic - How do I detect Opera/Netscape/IE?
-----------------------------------------------------------------------

The `` navigator '' object contains strings which
specify the browser and version; however, this is in general not
very genuine. Mozilla (and therefore Netscape 6+) allows this to
be freely set, and Opera and IE allow it to be modified. There
are also at least 25 other javascript capable browsers with
their own strings here.

Generally though, you don't need to identify which browser is
being used. There are alternative techniques, but which one you
choose depends on why you want to redirect browsers. If it's to
offer different CSS stylesheets, then

http://w3development.de/css/hide_css_from_browsers/

shows many techniques. For Scripting, _object_ detection
is a better method to use.

http://www.quirksmode.org/js/support.html

It is also known as feature detection.

Object/feature detection means checking that the object you wish
to use is supported by the browser before using it. This means
that you don't need to know what browsers support what methods,
and your code will automatically be usable on any browser that
can execute it.

if (document.getElementById &&
document.getElementById('el') &&
document.getElementById('el').style ) {
// We know that this browser supports getElementByID and has
// a style object, so we can set a style property.
document.getElementById('el').style.color="red";
}

Browser bugs can often be detected and overcome in similar ways.

http://www.jibbering.com/faq/faq_not...er_detect.html

http://developer.apple.com/internet/...detection.html


===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      09-08-2006
FAQ server said the following on 9/7/2006 7:00 PM:
> -----------------------------------------------------------------------
> FAQ Topic - How do I detect Opera/Netscape/IE?
> -----------------------------------------------------------------------
>
> The `` navigator ''

<snip>

That needs to be modified so that it uses the same quoting on both
sides. The FAQ itself does not have that issue.


--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      09-08-2006
Randy Webb wrote:

> FAQ server said the following on 9/7/2006 7:00 PM:
> > `` navigator ''

>
> That needs to be modified so that it uses the same quoting on both
> sides. The FAQ itself does not have that issue.


Okay, <icode> is now regexed to '' , so `` navigator '' would become
'' navigator '' . Here is the complete current list:

"p" => "\n",
"/p" => "\n",
"em" => "_",
"/em" => "_",
"url" => "\n\n",
"/url" => "\n\n",
"ul" => "\n",
"/ul" => "\n",
"li" => "* ",
"/li" => "",
"moreinfo" => "\n\n",
"/moreinfo" => "\n\n",
"resource" => "\n\n",
"/resource" => "\n\n",
"icode" => "'' ",
"/icode" => " ''",
"code" => "\n\n",
"/code" => "\n\n",

Other tags than the above and besides <CONTENTS>, <CONTENT>, <FAQ>,
<TITLE> are regexed to empty string.

--
Bart

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-08-2006
JRS: In article <4500a477$0$75039$(E-Mail Removed)>, dated Thu,
7 Sep 2006 23:00:01 remote, seen in news:comp.lang.javascript, FAQ
server <(E-Mail Removed)> posted :

>FAQ Topic - How do I detect Opera/Netscape/IE?



>Object/feature detection means checking that the object you wish
>to use is supported by the browser before using it.


That's Object detection. Feature detection should be used for detecting
what the Object, method, or other entity actually does. An example
might be using new Date("01/02/03") and seeing what day, month,
year, and century it gives. Or checking to see whether /a??/ is an
acceptable RegExp.



In article <(E-Mail Removed)>, dated Thu, 7
Sep 2006 22:13:13 remote, seen in news:comp.lang.javascript, Randy Webb
<(E-Mail Removed)> posted :
>> The `` navigator ''

><snip>
>
>That needs to be modified so that it uses the same quoting on both
>sides.


Not necessarily. If the characters are generally available, and
correctly reproduced in all likely fonts, then « and » (squashed << and
>>) would be a good choice, since they are characters well-known (to the

literate) to be quotes yet not in use in English or ECMAScript.

Perhaps ECMAscript or ECMAScript should be the generic term in the FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      09-08-2006
JRS: In article <(E-Mail Removed)>, dated
Thu, 7 Sep 2006 22:13:13 remote, seen in news:comp.lang.javascript,
Randy Webb <(E-Mail Removed)> posted :

>> The `` navigator ''

><snip>
>
>That needs to be modified so that it uses the same quoting on both
>sides.


Not necessarily. If the characters are generally available, and
correctly reproduced in all likely fonts, then « and » would be a good
choice, since they are characters well-known (to the literate) to be
quotes yet not in use in English or ECMAScript. There may be other
possibilities.

Perhaps ECMAscript or ECMAScript should be the generic term in the FAQ.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-09-2006
Dr John Stockton wrote:
> FAQ server posted :
>>FAQ Topic - How do I detect Opera/Netscape/IE?

>
>>Object/feature detection means checking that the object
>>you wish to use is supported by the browser before using it.

>
> That's Object detection. Feature detection should be used
> for detecting what the Object, method, or other entity
> actually does.

<snip>

Isn't the object (if present) a feature of the browser's object model? I
have always promoted "feature detection" over "object detection" as the
term for the type of testing required because it encompassed the
detection of the existence of objects/properties and their behaviour.

(That and because "object detection" is often used to label the
object-inference type testing that is used for 'browser detecting' (and
the basis of other irrational assumptions) and so can be easily be
misinterpreted. The term "feature detection" has also been applied to
object inference, but that is significantly less common than using
"object detection".)

Richard.


 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      09-09-2006
Dr John Stockton wrote:

> JRS: In article <(E-Mail Removed)>, dated
> Thu, 7 Sep 2006 22:13:13 remote, seen in news:comp.lang.javascript,
> Randy Webb <(E-Mail Removed)> posted :
>
> >> The `` navigator ''

> ><snip>
> >
> >That needs to be modified so that it uses the same quoting on both
> >sides.

>
> Not necessarily. If the characters are generally available, and
> correctly reproduced in all likely fonts, then « and » would be a good
> choice, since they are characters well-known (to the literate) to be
> quotes yet not in use in English or ECMAScript.


I think that's a good idea and I adapted the programme as such. « and
» are also less likely to occur inside javascript code compared to
single quotes, thus improving readability and unambiguity.

While non-ASCII, « and » should not cause problems:

- They're part of ISO-8859-1 (Latin-1, from 1987), which is the
character set in which the daily Usenet message is sent;
- ISO-8859-1 is the 'default' character set on the internet since the
IANA registered it as such in 1992. It's since then the standardized
default encoding of documents delivered via HTTP with a MIME type
beginning with "text/";
- It's pretty safe to state that a news reader that can't handle
ISO-8859-1 is no good;
- ISO-8859-1 is the basic 'pure' Latin charset after ASCII (there are
many OS/vendor variants on it though)
- Using «» this way is exactly just as "dangerous" as using é or §
or à.

> There may be other possibilities.


Not that much, I'm afraid (unless you take extra "risks" of course):

http://www.htmlhelp.com/reference/charset/latin1.gif
http://www.htmlhelp.com/reference/charset/

--
Bart

 
Reply With Quote
 
John G Harris
Guest
Posts: n/a
 
      09-09-2006
In article <(E-Mail Removed)>, Dr John Stockton
<(E-Mail Removed)> writes

<snip>
>Perhaps ECMAscript or ECMAScript should be the generic term in the FAQ.


ECMAScript (capital S says ECMA) is only the core language. It doesn't
include i/o facilities such as Alert and file access.

The advantage of "javascript" is that the lack of capital letters
suggests that it's not restricted to the products of one company or
organisation.

John
--
John Harris
 
Reply With Quote
 
Bart Van der Donck
Guest
Posts: n/a
 
      09-10-2006
Bart Van der Donck wrote:

> While non-ASCII, « and » should not cause problems
> [...]


Actually they did, but on a different level than I expected. Last night
at 00:00 WET the bot said:

"Error: XML file not well-formed after Usenet format regexes."

Obviously, the problem was at « and ». It appears that 127-255
characters result in invalid XML if the charset isn't specified. This
XML is okay:

<foo>bar</foo>

While this throws an error because of the "invalid character" (read:
non-ASCII):

<foo>bar « more bar</foo>

I've found a workaround so that this error is now solved. I just made
bot post today's message by hand (so today's delay was 9h15 min).

My tests show that this problem would not have occurred if the first
line of http://www.jibbering.com/faq/index.xml would have been in a
standard <?xml...?> format. This is valid XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<foo>bar « more bar</foo>

I kindly request the FAQ maintainer to add

<?xml version="1.0" encoding="ISO-8859-1"?>

as initial line of http://www.jibbering.com/faq/index.xml.

Thanks,

--
Bart

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-10-2006
Bart Van der Donck wrote:
<snip>
> I kindly request the FAQ maintainer to add
>
> <?xml version="1.0" encoding="ISO-8859-1"?>

<snip>

What is wrong with the UTF-8 default for XML?

Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ Topic - How do I detect Opera/Safari/IE? (2012-02-19) FAQ server Javascript 0 02-19-2012 12:00 AM
OFF TOPIC:Re: C compiler question (I hope this is on topic) jacob navia C Programming 5 05-30-2010 02:22 PM
FAQ Topic - What questions are on-topic for CLJ? (2008-10-16) FAQ server Javascript 1 10-16-2008 12:03 PM
There are no more messages on this topic. All messages in this topic may have expired or been deleted Coach 02 Computer Support 1 03-12-2007 03:44 PM



Advertisments