473,799 Members | 3,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

browser detection and css

Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.

<html>
<head>

<script language="JavaS cript"><!--
browser_version = parseInt(naviga tor.appVersion) ;
browser_type = navigator.appNa me;

if (browser_type == "Microsoft Internet Explorer" && (browser_versio n
>= 4)) {
document.write( "<I>You appear to be using Microsoft Internet
Explorer</I>");
}
else if (browser_type == "Netscape" && (browser_versio n >= 4)) {
document.write( "<I>You appear to be using Netscape</I>");
}
// --></script>

<script language="JavaS cript"><!--
browser_version = parseInt(naviga tor.appVersion) ;
browser_type = navigator.appNa me;

if (browser_type == "Microsoft Internet Explorer" && (browser_versio n
>= 4)) {
document.write( "<link REL='iexplorer. css' TYPE='text/css'>");
}

else if (browser_type == "Netscape" && (browser_versio n >= 4)) {
document.write( "<link REL='netscape.c ss' TYPE='text/css'>");
}

// --></script>

</head>
<body>

Oct 1 '06 #1
12 1826
VK

jn*****@googlem ail.com wrote:
Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.

<html>
<head>

<script language="JavaS cript"><!--
browser_version = parseInt(naviga tor.appVersion) ;
browser_type = navigator.appNa me;

if (browser_type == "Microsoft Internet Explorer" && (browser_versio n
= 4)) {
document.write( "<I>You appear to be using Microsoft Internet
Explorer</I>");
}
else if (browser_type == "Netscape" && (browser_versio n >= 4)) {
That's an unexploded ammo from the Browser Wars Where did you dig it
out? Put it back into soil immediately!

There is not Netscape 4 anymore, a bounch of browsers has "Internet
Explorer" added in the userAgent string and any workarounds of that
time has no relevance to this time anyway. If you tell what kind of
particular discrepancies you want to deal with, we'll find a working
modern solution.

Oct 1 '06 #2
jn*****@googlem ail.com wrote:
Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.
Why don't you just use IE specific conditional includes?

<!--[if IE ]>
<link ..... />
<![endif]-->
--
Ian Collins.
Oct 1 '06 #3
On or about 10/1/2006 3:37 PM, it came to pass that Ian Collins wrote:
jn*****@googlem ail.com wrote:
>Help needed, the script below detects the correct browser but doesn't
select the correct CSS file. Also how to call it from an external js
file so as not to repeat it in every page.
Why don't you just use IE specific conditional includes?

<!--[if IE ]>
<link ..... />
<![endif]-->

The following works for me and allows IE7 and all other browser to use
my default css. However, it does not pass the W3C HTML validation.

<!--[if lte IE 6]>
<LINK REL="stylesheet " TYPE="text/css" HREF="CSS/IE5.css">
<![endif]-->
<![if gte IE 7]>
<LINK REL="stylesheet " TYPE="text/css" HREF="CSS/Default.css">
<![endif]>
Oct 2 '06 #4
on Oct 2 2006 2:01 am totalstranger wrote:
The following works for me and allows IE7 and all other browser to use
my default css. However, it does not pass the W3C HTML validation.
Thanks for the responces, I'll try this out.

"If you tell what kind of particular discrepancies you want to deal
with, we'll find a working modern solution.", VK

Problem: The web site looks different under Firefox and Iexplorer 6.
The solution is to load a different CSS file depending on the browser.
I would like to link each page to a javascript browser detection script
so I don't need to paste the script into every html file.

Oct 2 '06 #5
jn*****@googlem ail.com wrote:
Problem: The web site looks different under Firefox and Iexplorer 6.
This is not necessarily a problem. Why must it look identical?
The solution is to load a different CSS file depending on the browser.
A better solution might be to write more portable, bullet-proof css.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 2 '06 #6
Mon, Oct 2 2006 4:31 pm Matt Kruse wrote:
This is not necessarily a problem. Why must it look identical?
I use Firefox, most of the viewers will be using Iexplorer. The fonts
are different sizes and images don't position correctly.
The solution is to load a different CSS file depending on the browser.
A better solution might be to write more portable, bullet-proof css.
I've tried such portable CSS files. They don't word as advertised and I
don't understand enough of the syntax to write one. How difficult is it
of the browser developers to get them displaying the same.

Here's one that shows promise ..
http://www.digiways.com/articles/php...cssmethod.html

Oct 2 '06 #7
jn*****@googlem ail.com wrote:
I use Firefox, most of the viewers will be using Iexplorer. The fonts
are different sizes and images don't position correctly.
Do you have an example url?
If images position incorrectly just because of font size, you are probably
misusing css or need to reconsider your design.
Here's one that shows promise ..
http://www.digiways.com/articles/php...cssmethod.html
Yuck. Don't look at the user agent to serve up different css! This is always
bad.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 2 '06 #8
Do you have an example url?

Not yet, at the rate I'm going at maybe in a few weeks
Yuck. Don't look at the user agent to serve
up different css! This is always bad.
Ok, so its back to a single css with conditionals for Iexplorer. By the
way this script does work except it won't load opera.css under Opera
9.02

document.write( '<link rel="stylesheet " href="http://somesite.com/');
var agt=navigator.u serAgent.toLowe rCase();
if (agt.indexOf('o pera') != -1) document.write( 'opera.css');
else if (agt.indexOf('g ecko') != -1) document.write( 'mozilla.css');
else if (agt.indexOf('m sie') != -1) document.write( 'iexplorer.css' );
else document.write( 'default.css');
document.write( '" type="text/css">');

Oct 2 '06 #9
Matt Kruse wrote:
jn*****@googlem ail.com wrote:
>>Problem: The web site looks different under Firefox and Iexplorer 6.


This is not necessarily a problem. Why must it look identical?

>>The solution is to load a different CSS file depending on the browser.


A better solution might be to write more portable, bullet-proof css.
I normally end up with a few entries in an IE specific css file to cope
with the things IE doesn't implement, like :hover.

I don't think it's possible to get table borders consistent without IE
specific entries.

--
Ian Collins.
Oct 2 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
10074
by: Szar | last post by:
JS noob. I've seen plenty of browser detection scripts but they all seem to be slightly different and don't really fit my needs. I have various places where if the browser is IE I'd like to display else . For example, if a browser is IE I want to use this CSS file otherwise use a different one and if it's IE make this cell x pixels high else make it y pixels high. I'm sure this is easy, please excuse my stupidity. Steve.
17
2562
by: lawrence | last post by:
How is it possible that the question "How do I detect which browser the user has" is missing from this FAQ: http://www.faqts.com/knowledge_base/index.phtml/fid/125 and is only here on this with a link to old information that suggests use of "navigator": http://developer.irt.org/script/43.htm
8
4550
by: R. Smits | last post by:
I've have got this script, the only thing I want to be changed is the first part. It has to detect IE version 6 instead of just "Microsoft Internet Explorer". Can somebody help me out? I tried "Microsoft Internet Explorer 6" but that doesn't work. <SCRIPT LANGUAGE="Javascript"> <!-- bName = navigator.appName; if (bName =="Microsoft Internet Explorer") { document.write('<link media="screen" rel="STYLESHEET" type="text/css"
8
1688
by: Jimnbigd | last post by:
What is the recommended code to test browser type, for conditional processing in Javascript? I have seen tests for "document.all". I have seen tests for the actual browser name, or substrings in the browser name. What do you all recommend? Thanks...Jim...
7
1936
by: phal | last post by:
Hi I think there are many different browsers to browse to the Internet, how can I write the javascript to identify different browser and display according to the users. Some browser disable the javascript by default or by the user, how can i solve this problem if the javascript is disable. thank you
4
2581
by: trpost | last post by:
I am looking for a script using javascript to pull browser information including, browser type and version, OS info, plugins (flash, acrobat, media player, etc), java version, etc. that will work on IE/Firefox. I am looking for detalis similar to what is available at: http://www.webreference.com/tools/browser/_browserhawk.html Thanks!
15
2330
by: CMM | last post by:
So I'm half way through overseeing a large project in ASP.NET 2.0. My superiors have decided that it would be nice if we ensured the site worked on all the major platforms (as they see it: IE, FireFox, and Safari). We've made heavy usage of the new MENU control and other intrinsic 2.0 controls.... nothing fancy! just using ASP.NET's built-in controls and very nice, pervasive, and clean usage of CSS. Now I find after more testing that the...
16
2361
by: petermichaux | last post by:
Hi, Does anyone have a a cross-browser setOpacity function that does not use browser sniffing? I looked at the Yahoo! UI function and it detects IE by looking for window.ActiveXObject. I also looked at Scriptaculous and it uses navigator.userAgent. Thanks, Peter
7
3004
by: Nathan Sokalski | last post by:
I want to make sure I am doing a browser detection that will work once IE7 is released. My current detection statement (written using VB.NET) is: If Me.Request.Browser.Browser.ToUpper() = "IE" Then 'Code to use for Internet Explorer browsers Else 'Code to use for browsers other than Internet Explorer End If
10
3265
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations where you could improve the application by detecting the browser vendor/version. Some of the posters here disagreed. Since then, I've had to deal with a few of these cases; some of them could be rewritten to use object detection, and some couldn't....
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
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 we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.