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

a script for each browser ?

P: n/a
Hi,

I would like to write a script that will load a js file according to the
browser used.
Here is the suggested code :

****
function detectBrowser()
{
var browser=navigator.appName;
if ((browser=="Netscape"))
{
Load the netscape.js file;
}
else
{
load others.js;
}
}
*****
So, how could I code the "load the *js code" ?
Thanks for your help.
Rémi.

Dec 5 '07 #1
Share this Question
Share on Google+
15 Replies


P: n/a
remi said the following on 12/5/2007 5:59 PM:
Hi,

I would like to write a script that will load a js file according to the
browser used.
Why?
Here is the suggested code :
Throw it away, it is junk.
****
function detectBrowser()
{
var browser=navigator.appName;
There is your first problem. Attempting to identify *anything* based on
the navigator.appName
So, how could I code the "load the *js code" ?
First, you might try explaining why you think you need two .js files to
start with.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 5 '07 #2

P: n/a
remi wrote:
****
function detectBrowser()
{
var browser=navigator.appName;
if ((browser=="Netscape"))
{
Load the netscape.js file;
}
else
{
load others.js;
}
}
*****
So, how could I code the "load the *js code" ?
Thanks for your help.
What would you do differently for Netscape?
Mick
Dec 5 '07 #3

P: n/a
Le Wed, 05 Dec 2007 18:31:09 -0500, Randy Webb a écrit*:
remi said the following on 12/5/2007 5:59 PM:
>Hi,

I would like to write a script that will load a js file according to
the browser used.

Why?
>Here is the suggested code :

Throw it away, it is junk.
>****
function detectBrowser()
{
var browser=navigator.appName;

There is your first problem. Attempting to identify *anything* based on
the navigator.appName
>So, how could I code the "load the *js code" ?

First, you might try explaining why you think you need two .js files to
start with.
Ok, it is a bit special. The aim is to be able to render dynamic SVG
files (SMIL animation). SVG is into a XHTML file.

Opera renders them properly (for the use I need)
Firefox and others not yet (IE never) except if I load a script called
smilScript.js that will emulate rendering engine by script.

The matter is that if I have the script loaded into Opera, the animation
are a bit buggy and slow. I think that the script conflicts with Opera's
built-in rendering engine.

So I would like to only load this great script if needed that is to say
if the browser is not Opera.

Thanks for your replies.
Rémi.

Dec 6 '07 #4

P: n/a
rmi said the following on 12/6/2007 11:01 AM:
Le Wed, 05 Dec 2007 18:31:09 -0500, Randy Webb a crit :
>remi said the following on 12/5/2007 5:59 PM:
>>Hi,

I would like to write a script that will load a js file according to
the browser used.
Why?
>>Here is the suggested code :
Throw it away, it is junk.
>>****
function detectBrowser()
{
var browser=navigator.appName;
There is your first problem. Attempting to identify *anything* based on
the navigator.appName
>>So, how could I code the "load the *js code" ?
First, you might try explaining why you think you need two .js files to
start with.

Ok, it is a bit special. The aim is to be able to render dynamic SVG
files (SMIL animation). SVG is into a XHTML file.

Opera renders them properly (for the use I need)
Firefox and others not yet (IE never) except if I load a script called
smilScript.js that will emulate rendering engine by script.

The matter is that if I have the script loaded into Opera, the animation
are a bit buggy and slow. I think that the script conflicts with Opera's
built-in rendering engine.

So I would like to only load this great script if needed that is to say
if the browser is not Opera.
I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file should
do that). Then, it doesn't matter what browser it is. If it supports
what you want to do, then it supports it. If it doesn't, then it falls
back out.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 6 '07 #5

P: n/a
Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a écrit*:
rémi said the following on 12/6/2007 11:01 AM:
>Le Wed, 05 Dec 2007 18:31:09 -0500, Randy Webb a écrit :
>>remi said the following on 12/5/2007 5:59 PM:
Hi,

I would like to write a script that will load a js file according to
the browser used.
Why?

Here is the suggested code :
Throw it away, it is junk.

****
function detectBrowser()
{
var browser=navigator.appName;
There is your first problem. Attempting to identify *anything* based
on the navigator.appName

So, how could I code the "load the *js code" ?
First, you might try explaining why you think you need two .js files
to start with.

Ok, it is a bit special. The aim is to be able to render dynamic SVG
files (SMIL animation). SVG is into a XHTML file.

Opera renders them properly (for the use I need) Firefox and others not
yet (IE never) except if I load a script called smilScript.js that will
emulate rendering engine by script.

The matter is that if I have the script loaded into Opera, the
animation are a bit buggy and slow. I think that the script conflicts
with Opera's built-in rendering engine.

So I would like to only load this great script if needed that is to say
if the browser is not Opera.

I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file should
do that). Then, it doesn't matter what browser it is. If it supports
what you want to do, then it supports it. If it doesn't, then it falls
back out.
Yes you are right, but I know wich browser natively support it. At the
moment there is only opera. Some others can do it with a plugin. So
navigator.appName should do the job (?).

BTW, I don't have a clue on how to test, with a script, if a feature is
supported or not.
Thanks.
Rémi.

Dec 6 '07 #6

P: n/a
On Dec 6, 12:23 pm, rmi <nos...@merci.comwrote:
Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a crit :
rmi said the following on 12/6/2007 11:01 AM:
Le Wed, 05 Dec 2007 18:31:09 -0500, Randy Webb a crit :
>remi said the following on 12/5/2007 5:59 PM:
Hi,
>>I would like to write a script that will load a js file according to
the browser used.
Why?
>>Here is the suggested code :
Throw it away, it is junk.
>>****
function detectBrowser()
{
var browser=navigator.appName;
There is your first problem. Attempting to identify *anything* based
on the navigator.appName
>>So, how could I code the "load the *js code" ?
First, you might try explaining why you think you need two .js files
to start with.
Ok, it is a bit special. The aim is to be able to render dynamic SVG
files (SMIL animation). SVG is into a XHTML file.
Opera renders them properly (for the use I need) Firefox and others not
yet (IE never) except if I load a script called smilScript.js that will
emulate rendering engine by script.
The matter is that if I have the script loaded into Opera, the
animation are a bit buggy and slow. I think that the script conflicts
with Opera's built-in rendering engine.
So I would like to only load this great script if needed that is to say
if the browser is not Opera.
I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file should
do that). Then, it doesn't matter what browser it is. If it supports
what you want to do, then it supports it. If it doesn't, then it falls
back out.

Yes you are right, but I know wich browser natively support it. At the
moment there is only opera. Some others can do it with a plugin. So
navigator.appName should do the job (?).
The navigator.appName property is worthless. If you really have such
a special case that you need to exclude only Opera, and assuming there
is no feature detection for the required level of SVG support, you can
test for the global opera object. Before you resort to that though,
you should think if there are specific SVG features that are present
in Opera, but not in the other browsers.
>
BTW, I don't have a clue on how to test, with a script, if a feature is
supported or not.
You should learn how to do that first. Do you at least know how to
test if a feature is present? If present, features can be tried and
sometimes results can be measured in a way that differentiates proper
implementations from broken ones.
Dec 6 '07 #7

P: n/a
In comp.lang.javascript message <9s*********************@giganews.com>,
Wed, 5 Dec 2007 18:31:09, Randy Webb <Hi************@aol.composted:
>remi said the following on 12/5/2007 5:59 PM:
>Hi,
I would like to write a script that will load a js file according to
the browser used.

Why?
>Here is the suggested code :

Throw it away, it is junk.
>****
function detectBrowser()
{
var browser=navigator.appName;

There is your first problem. Attempting to identify *anything* based on
the navigator.appName
>So, how could I code the "load the *js code" ?

First, you might try explaining why you think you need two .js files to
start with.

Rather than being merely grumpy in your reply, why not be constructive
and give a direct citation of a useful reference? FAQ 4.26, for
example.

<FAQENTRYIn FAQ 4.26, insert "correctly" before "supported"; and add
else /* ??? */
to the code.

The page that you cite in sig line 4 is a poor example of best practices
in general, as it fails Opera Ctrl-Alt-V W3 HTML validation in a manner
which appears largely fixable without loss of functionality. And the
page that you cite in sig line 3 is only tentatively valid.

Firefox is now 2.0.0.11.

BTW, why do you cite in the FAQ pages that you cannot understand? The
only logical reason for that would be an expectation that FAQ readers
are smarter than you are.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 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)
Dec 6 '07 #8

P: n/a
rmi wrote:
Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a crit :
>I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file should
do that). Then, it doesn't matter what browser it is. If it supports
what you want to do, then it supports it. If it doesn't, then it falls
back out.

Yes you are right, but I know wich browser natively support it.
You don't even know a small subset of those.
At the moment there is only opera.
Your information is heavily outdated. Example, all Gecko 1.8+ based UAs
support it natively, too. That includes, for example, Firefox 1.5+ (1.5
was released on 2005-11-29).

http://www.mozilla.org/projects/svg/status.html
[...]
So navigator.appName should do the job (?).
Never ever does it. http://PointedEars.de/scripts/test/whatami
BTW, I don't have a clue on how to test, with a script, if a feature is
supported or not.
I doubt that for this feature test you will need client-side scripting at
all. HTML provides for intrinsic fallback.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Dec 6 '07 #9

P: n/a
Le Thu, 06 Dec 2007 22:15:57 +0100, Thomas 'PointedEars' Lahn a écrit:
rémi wrote:
>Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a écrit :
>>I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file
should do that). Then, it doesn't matter what browser it is. If it
supports what you want to do, then it supports it. If it doesn't, then
it falls back out.

Yes you are right, but I know wich browser natively support it.

You don't even know a small subset of those.
>At the moment there is only opera.

Your information is heavily outdated. Example, all Gecko 1.8+ based UAs
support it natively, too. That includes, for example, Firefox 1.5+ (1.5
was released on 2005-11-29).

http://www.mozilla.org/projects/svg/status.html
I am talking about declarative animation in SVG. Not static SVG.
You can have a look here at the Animation Module part of the page you
mentionned.

I know that the only browser to support it a the moment (natively) is
Opera.

It is the reason why this choice to detect browser name is good for me.

To be frank, I am very eager to have it supported in FF that I used much
more.
>
>[...]
So navigator.appName should do the job (?).

Never ever does it. http://PointedEars.de/scripts/test/whatami
Thanks for this link.
For my use, it doesn't matter is a user wants to fake navigator.appName
or navigator.userAgent
He won't have the animation working properly. What do you think of that
apples ? ;-)
My script is not intended to be used commercialy or event
professionnaly ! It is just for me and a few geeks willing to spend spare
time palying with computers.

All I need to know is how to load a script if navigator.appName is
Netscape.

I know this is junk, evil and I will flagelate myslef for hours because I
have done this great sin. Oh Lord, pardon me but... Do I have the
choice ? ;-)

Rémi.

Dec 7 '07 #10

P: n/a
On Dec 7, 9:28 am, remi <r...@nospam.orgwrote:
Le Thu, 06 Dec 2007 22:15:57 +0100, Thomas 'PointedEars' Lahn a crit:
rmi wrote:
Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a crit :
I think you want to load it if it supports SVG, irregardless of what
browser it is. That means you test for support (and the .js file
should do that). Then, it doesn't matter what browser it is. If it
supports what you want to do, then it supports it. If it doesn't, then
it falls back out.
Yes you are right, but I know wich browser natively support it.
You don't even know a small subset of those.
At the moment there is only opera.
Your information is heavily outdated. Example, all Gecko 1.8+ based UAs
support it natively, too. That includes, for example, Firefox 1.5+ (1.5
was released on 2005-11-29).
http://www.mozilla.org/projects/svg/status.html

I am talking about declarative animation in SVG. Not static SVG.
You can have a look here at the Animation Module part of the page you
mentionned.

I know that the only browser to support it a the moment (natively) is
Opera.

It is the reason why this choice to detect browser name is good for me.

To be frank, I am very eager to have it supported in FF that I used much
more.
[...]
So navigator.appName should do the job (?).
Never ever does it. http://PointedEars.de/scripts/test/whatami

Thanks for this link.
For my use, it doesn't matter is a user wants to fake navigator.appName
or navigator.userAgent
He won't have the animation working properly. What do you think of that
apples ? ;-)
Rotten. Never mind users. IE has spoofed Mozilla since the mid 90's.
My script is not intended to be used commercialy or event
professionnaly ! It is just for me and a few geeks willing to spend spare
time palying with computers.

All I need to know is how to load a script if navigator.appName is
Netscape.
How about if it is not Opera? I gave you the answer to that if you
want to resort to browser sniffing (!window.opera.)
Dec 7 '07 #11

P: n/a
Thanks for your reply,

Le Fri, 07 Dec 2007 10:09:34 -0800, David Mark a écrit*:
On Dec 7, 9:28 am, remi <r...@nospam.orgwrote:
[...]
>All I need to know is how to load a script if navigator.appName is
Netscape.

How about if it is not Opera? I gave you the answer to that if you want
to resort to browser sniffing (!window.opera.)
If it is Firefox : I need to load a script to emulate declarative
animation.

If it is Opera, that's OK : declarative animation in SVG are enough
supported for my use and I don't have to load a script (I must not to be
frank)

If it is IE : i dont' know/care as my users (me, myself, I and a few
unoccopied and polite enough friends) are on FF or Opera.
If it is other browser : need to try
If someone has spoofed appname : lol well done you cOwb0yZ ;-)

So anyone could tell me how to complete this piece of junk ?
****
function NoobWhoWroteThisWantsToDetectBrowserLol()
{
var browser=navigator.appName;
if ((browser=="Netscape"))
{
Load the netscape.js file;
}
else
{
load nothing and let things go !
}
}
*****
I promise I won't advice this to another noob who dare to ask !
Thanks ;-)
Rémi.

Dec 9 '07 #12

P: n/a
Dr J R Stockton said the following on 12/6/2007 7:43 AM:
In comp.lang.javascript message <9s*********************@giganews.com>,
Wed, 5 Dec 2007 18:31:09, Randy Webb <Hi************@aol.composted:
>remi said the following on 12/5/2007 5:59 PM:
>>Hi,
I would like to write a script that will load a js file according to
the browser used.
Why?
>>Here is the suggested code :
Throw it away, it is junk.
>>****
function detectBrowser()
{
var browser=navigator.appName;
There is your first problem. Attempting to identify *anything* based on
the navigator.appName
>>So, how could I code the "load the *js code" ?
First, you might try explaining why you think you need two .js files to
start with.


Rather than being merely grumpy in your reply, why not be constructive
and give a direct citation of a useful reference? FAQ 4.26, for example.
Yessuh Mastah, I dew whut yew want.
<FAQENTRYIn FAQ 4.26, insert "correctly" before "supported"; and add
else /* ??? */
to the code.
FAQ5.1, paragraph 1, last sentence.
The page that you cite in sig line 4 is a poor example of best practices
in general, as it fails Opera Ctrl-Alt-V W3 HTML validation in a manner
which appears largely fixable without loss of functionality. And the
page that you cite in sig line 3 is only tentatively valid.
Then sue me.
Firefox is now 2.0.0.11.
That's nice. Need a URL?
BTW, why do you cite in the FAQ pages that you cannot understand? The
only logical reason for that would be an expectation that FAQ readers
are smarter than you are.
I owe you an apology. I was wrong. You are dumber than I though you were.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 10 '07 #13

P: n/a
You might want to consider the free BrowserObject component at
http://www.browserobject.com

It provides browser detection as .NET component.
Dec 11 '07 #14

P: n/a
On Dec 11, 1:08 am, mkwong8...@hotmail.com wrote:
You might want to consider the free BrowserObject component athttp://www.browserobject.com

It provides browser detection as .NET component.
That is doubly worthless.
Dec 11 '07 #15

P: n/a
mk********@hotmail.com wrote:
You might want to consider the free BrowserObject component at
http://www.browserobject.com

It provides browser detection as .NET component.
Break, fly, wheel.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Dec 11 '07 #16

This discussion thread is closed

Replies have been disabled for this discussion.