a script for each browser ?

R

remi

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.
 
F

Fu Cheng

You should include a javascript loader in your html document. The
loader will detect the browser and load proper javascript files.

function detectBrowser()
{
var browser=navigator.appName;
if ((browser=="Netscape"))
{
// create a script
var script = document.createElement("script");
script.src = "netscape.js";
var head = // get head element
head.appendChild(script);
}

else
{
load others.js;
}
}
 
D

Dr J R Stockton

In comp.lang.javascript message said:
remi said the following on 12/5/2007 5:59 PM:

Throw it away, it is junk.


There is your first problem. Attempting to identify *anything* based on
the navigator.appName


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.

<FAQENTRY> In 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.
 
R

rémi

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

Throw it away, it is junk.


There is your first problem. Attempting to identify *anything* based on
the navigator.appName


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.
 
R

rémi

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:

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.
 
D

David Mark

Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a écrit :





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.
 
T

Thomas 'PointedEars' Lahn

rémi said:
Le Thu, 06 Dec 2007 12:07:24 -0500, Randy Webb a écrit :

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
 
R

remi

Le Thu, 06 Dec 2007 22:15:57 +0100, Thomas 'PointedEars' Lahn a écrit:
You don't even know a small subset of those.


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.
 
D

David Mark

Le Thu, 06 Dec 2007 22:15:57 +0100, Thomas 'PointedEars' Lahn a écrit:


You don't even know a small subset of those.
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).

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 (?).

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.)
 
R

rémi

Thanks for your reply,

Le Fri, 07 Dec 2007 10:09:34 -0800, David Mark a écrit :
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top