473,811 Members | 4,047 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
12 1828
jn*****@googlem ail.com wrote:
Ok, so its back to a single css with conditionals for Iexplorer.
Or not. Just design css that works in both. If there are compatability
problems, use different features or change your design to not rely on
unimplemented features.

There is going to be a lot of pain in the world when IE7 is released,
because people have used hacks and browser-detection to serve up different
css to different browsers. IE7 will support css much better than IE6, and
detection/hack scripts that previously tried to make sites look good in IE6
will start making sites look _bad_ in IE7.

BTW, if you aren't using a strict doctype, start with that. Using
cross-browser css becomes much easier once you are in strict mode.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 2 '06 #11
VK

jn*****@googlem ail.com wrote:
Problem: The web site looks different under Firefox and Iexplorer 6.
That is way too much of philosophy to be practical IMHO. Unless you are
doing some cutting edge stuff like behaviors/bindings/SVG/VML: you are
just dealing with simple box model discrepancies (x is lefter than
should, y is righter than I expect). Just read the "must have" article
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dnie60/html/cssenhancements .asp>
(a lot of good guys went out of business before this was forced to be
implemented, so at least read it). Then place one of suggested
DOCTYPE's to unify the fox model and try it over. Ask at ciwas for more
help.

Oct 2 '06 #12
On or about 10/2/2006 3:37 PM, it came to pass that Matt Kruse wrote:
jn*****@googlem ail.com wrote:
>Ok, so its back to a single css with conditionals for Iexplorer.

Or not. Just design css that works in both. If there are compatability
problems, use different features or change your design to not rely on
unimplemented features.

There is going to be a lot of pain in the world when IE7 is released,
because people have used hacks and browser-detection to serve up different
css to different browsers. IE7 will support css much better than IE6, and
detection/hack scripts that previously tried to make sites look good in IE6
will start making sites look _bad_ in IE7.

BTW, if you aren't using a strict doctype, start with that. Using
cross-browser css becomes much easier once you are in strict mode.
Yep I forgot to mention that little issue--to get IE7 to use standard
CSS it MUST be in strict mode versus quirks mode, otherwise your back in
IE5/6 territory.
Oct 3 '06 #13

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
2580
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
4554
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
1937
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
2583
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
2334
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
2364
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
3268
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
9724
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
10644
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
10394
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,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
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.