473,508 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to set javascript file for diff browsers

1 New Member
Hi,

I have 2 javascript file : IE.js and FF.js
If the browser is IE i want to use the IE.js file.
or if the browser is Firefox ill use the FF.js
the functions on IE and FF are the same but different in some codes not supported by either browser.

how can i do this in my html page?

for example

IF browser = IE
<script src="IE.js" type="text/javascript" />
ELSE
<script src="FF.js" type="text/javascript"/>

Thanks,[email removed]
Feb 20 '08 #1
3 1143
mrhoo
428 Contributor
You could load a small script from a src in the head of the document,
whose only job is to load the correct script:

Expand|Select|Wrap|Line Numbers
  1. (function(){
  2.     var url;
  3.     if(document.addEventListener)url= 'fs.js'
  4.     else if(document.attachEvent) url= 'ie.js';
  5.     if(url){
  6.         var el= document.createElement('script');
  7.         el.type= 'text/javascript';
  8.         el.src= url;
  9.         document.getElementsByTagName('head')[0].appendChild(el);
  10.     }
  11. })()
This syntax in a remote script called from the head will add the new script before the body is displayed.
You could easily call it onload instead, if you want the page up as quickly as possible.
Feb 20 '08 #2
rnd me
427 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. <!--[if IE]><script src="ie.js"></script>    <![endif]-->
  2.  
  3. <![if !IE]><script src="ff.js"></script>    <![endif]>
  4.  
Feb 21 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Expand|Select|Wrap|Line Numbers
  1. <!--[if IE]><script src="ie.js"></script>    <![endif]-->
  2.  
  3. <![if !IE]><script src="ff.js"></script>    <![endif]>
  4.  
Yep, conditional comments.

To the OP: you should consider if you could combine the two, though sometimes it's not possible. Have you thought about other browsers too?
Feb 21 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2508
by: Charley | last post by:
I've got a diff file that I think is a patch for a bunch of file in a directory. How do I apply this file? I thought it was #patch myfile.diff But that does nothing. I must be missing...
53
5656
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
16
1700
by: Christopher Benson-Manica | last post by:
Can anyone tell me which browsers implement Javascript 1.3? Specifically, which browsers will handle the identity operator (===) correctly? I ask because jslint suggests using it, but I don't want...
10
4553
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
8
3623
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
1
8728
by: senthilnathan1985 | last post by:
sir, am implementing javascript in my project am begineer to javascript and asp.net can you please help me for the following queries here am using one dropdownlist which contains number of...
17
2708
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
22
2756
by: giordan | last post by:
Hi all! I've wrote this code: <script type="text/javascript"> var largImg; var altImg; var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il...
8
4919
by: GiJeet | last post by:
hello, is it possible to determine the browser and version using javascript at runtime and apply a browser specific external .css file? If so, I'd appreciate code sample so I can see how it's...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.