Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: SV: Detect browser, but then direct to different external .js files (includes) based on browser/version


Message #1 by "Robert Nyman" <robert.nyman@c...> on Wed, 23 Oct 2002 16:31:31 +0200
This is just the sort of thing I'm looking for.  I'll try them both.

Thanks.

- Bradley

-----Original Message-----
From: Robert Nyman [mailto:robert.nyman@c...]
Sent: Wednesday, October 23, 2002 10:32 AM
To: javascript
Subject: [javascript] SV: Detect browser, but then direct to different
external .js files (includes) based on browser/version


Well, I can think of two different approaches:

1. document.write

For instance:

<script language=3D"JavaScript" type=3D"text/javascript">
<!--
	if(navigator.appName =3D=3D "Netscape" &&
parseInt(navigator.appVersion, 10) =3D=3D 4){
		document.write('<script language=3D"JavaScript"
type=3D"text/javascript" src=3D"oldNetscape.js"></script>');
	}
	else{
		document.write('<script language=3D"JavaScript"
type=3D"text/javascript" src=3D"DOMBrowsers.js"></script>');
	}
//-->
</script>

2. The DOM way

<script language=3D"JavaScript" type=3D"text/javascript" 
id=3D"ExtJSFile"
src=3D"oldNetscape.js"></script>
<script language=3D"JavaScript" type=3D"text/javascript">
<!--
	if(navigator.appName =3D=3D "Netscape" &&
parseInt(navigator.appVersion, 10) >=3D 5){
		document.getElementById(ExtJSFile).setAttribute("src",
"DOMBrowsers.js");
	}
//-->
</script>



/Robert


-----Ursprungligt meddelande-----
Fr=E5n: Bradley Wilson [mailto:bwilson@p...]
Skickat: den 23 oktober 2002 15:23
Till: javascript
=C4mne: [javascript] Detect browser, but then direct to different 
external
.js files (includes) based on browser/version


Help!!
I'm well aware of methods to detect browser, version, screen 
resolution,

op. system, etc., and perform "page redirects" based on those
determinations.

However, I don't want to point to a different web page; I want to point
to
a different external .js file.

I'm utilizing external JavaScript files to dynamically write HTML code
(in
other words, "includes"), and I have a situation where I would like to
run
different scripts based on the browser and version.  I've been unable 
to

find the property and method to perform this task.

Can somebody help, please.  Thanks.

- Bradley Wilson

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogram
me
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogram
me
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogram
me
r-20



---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogram
me
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogram
me
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogram
me
r-20

  Return to Index