Online Shopping : Computers : Internet : Web : CSS

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

54 of 62 people (87%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

Can I link to different style sheets, depending on the user's browser?

Apr 2nd, 2009 06:22
engatoo engatoo, Rockys rainwal, Raj Aryan, Denny De La Haye, Hiroto Sekine, Rey Nuٌez, http://indiatravelsguide.blogspot.com/


===== ( Perl solution ) =====
In my YAWNS package, I use the following code to detect which browser 
is
making the request and then select a stylesheet appropriately (the
stylesheet string is simply inserted into the generated HTML where
appropriate - personally I use HTML::Template, but the same method can
be used with plain CGI.pm code as well).
my $browser	= '100% Standards Compliant'; 	# mozilla/galeon/etc
my $style	= 'styles/default.css';
my $useragent	= '';
$useragent
= $ENV{'HTTP_USER_AGENT'} if $ENV{'HTTP_USER_AGENT'};
$browser = 'Netscape 4'	if $useragent =~ m/Mozilla.?4\./;
$browser = 'MSIE 4'	if $useragent =~ m/MSIE/;
$browser = 'MSIE 5.0'	if $useragent =~ m/MSIE.?5\./;
$browser = 'MSIE 5.5'	if $useragent =~ m/MSIE.?5.?5/;
$browser = 'MSIE 6'	if $useragent =~ m/MSIE.?6\./;
$browser = 'Opera'	if $useragent =~ m/Opera/;
$browser = 'Konqueror'	if $useragent =~ m/Konqueror/;
if ( $browser eq 'Netscape 4' ) {
	# terrible CSS support, need to repeatedly redefine attributes
	$style = 'styles/ns4.css';
} elsif ( ( $browser =~ m/MSIE/ ) 
	or ( $browser eq 'Opera' ) 
	or ( $browser eq 'Konqueror' ) ) {
	# poor CSS support - have to specify absolute sizes for fonts
	$style = 'styles/ie.css';
}
===== ( JavaScript solution ) =====
This example shows one method of detecting a user's browser and link 
the current document to a corresponding style sheet. This is 
implemented in two parts: the main script which is written as a 
separate .js file, and a calling script written within the HEAD of 
each 
page that will link to the style sheets.
STEP 1: Copy this code and save it as a separate file, for example, as 
css.js
<!--
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt
(navigator.appVersion)>= 4 )) {
  document.write('<link rel="stylesheet" type="text/css" 
href="ie45.css">')}
else {
  if (navigator.appName == "Netscape"){
    if (parseInt(navigator.appVersion)>= 5 ){
      document.write('<link rel="stylesheet" type="text/css" 
href="ns6.css">')}
    else {
      document.write('<link rel="stylesheet" type="text/css" 
href="ns4.css">')}
    }
  else {
    document.write('<link rel="stylesheet" type="text/css" 
href="default.css">')}
}
//-->
Note that the above example assumes that you have four style sheets: 
one for IE 4.0 and later, one for Netscape 5.0 and later, one for 
Netsc
ape versions less than 5, and one for the rest. Make sure that 
each <LINK href= ... > in the script points to the proper path and 
filename of your style sheets.
STEP 2: Copy this code into the HEAD of each HTML document that you 
intend to link to the stylesheets. 
<script language="JavaScript" src="css.js"></script>
If you change the name and/or location of the main .js file in Step 1, 
make sure that the <script src= ... > in Step 2 above references the 
correct path and filename of the .js file, or the script will not be 
called and thus not function as intended.
with IE4+: another option as below;
gLNGflag is a global variable to be set "language code" in other 
function.
--------------< source code sample >------------
<script LANGUAGE="JavaScript">
<!--
if (IECheck( 5, "../index.htm" )){
	LNGCheck( "zz", "", "", "" );
}
var lang;
switch(gLNGflag){
	case "ja":
		lang = "jp";
		break;
	case "zt":
		lang = "ct";
		break;
	default:
		lang = "us";
}
var css = "<link REL='stylesheet' TYPE='text/css' HREF='doc/vb7" + 
lang 
+".css'>";
var sc1 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7whd" + lang 
+ ".js'></scr" + "ipt>";
var sc2 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7chd" + lang 
+ ".js'></scr" + "ipt>";
var sc3 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7ihd" + lang 
+ ".js'></scr" + "ipt>";
var sc4 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7vhd" + lang 
+ ".js'></scr" + "ipt>";
var sc5 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7ltool" + 
lang 
+ ".js'></scr" + "ipt>";
var sc6 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7wtool" + 
lang 
+ ".js'></scr" + "ipt>";
var sc7 = "<scr" + "ipt LANGUAGE='JavaScript' SRC='doc/vb7main" + lang 
+ ".js'></scr" + "ipt>";
document.write(css);
document.write(sc1);
document.write(sc2);
document.write(sc3);
document.write(sc4);
document.write(sc5);
document.write(sc6);
document.write(sc7);
// -->
http://www.jaipurtravelguide.com/
http://www.jaipurtravels.com/
http://www.jaipurjaipur.com/
http://www.jaipurtourismguide.com/
http://www.rajasthantravelsguide.com/
http://www.rajasthantravelguide.co.in/
http://www.travelpackagerajasthan.com/
http://www.namaskarindiatravels.com/
http://www.indianhotelsindia.com/
http://www.travelpackageindia.com/
http://www.navyatravels.com/
http://www.hillstationindiatour.com/
http://www.wildlifeindiatravel.com/ 
http://www.pushkartravels.com/
http://www.udaipurtravels.com/
http://www.agratravels.com/
http://indiantravelguide.co.in/
http://www.traveltoindia.biz/
http://www.info4india.com/
http://www.indiantravelsguide.com/
http://www.indiantravelguideindia.com/
http://rajasthantravelguide.wordpress.com/
http://attractioninjaipur.blogspot.com/
http://jaipurtravelsguide.blogspot.com/
http://hoteles-en-la-india.blogspot.com/
http://jaipurguiadeviajes.blogspot.com/
http://jaipurrajasthanindia.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://wildlifeindiatravel.blogspot.com/
http://indiantravelguideindia.blogspot.com/
http://indianhotelsindia.blogspot.com/
http://rajasthantravelsguide.blogspot.com/
http://pushkartravels.blogspot.com/
http://indiatravelsguide.blogspot.com/
http://goaguidedevoyage.blogspot.com/
http://goatravelsguide.blogspot.com/
http://indiaguadeviajes.blogspot.com/
http://htelseninde.blogspot.com/
http://indienguidedevoyage.blogspot.com/
http://indianhillstationsindiatravel.blogspot.com/
http://jaipurtravelguiderajasthan.blogspot.com/
http://hillstationinindia.blogspot.com/
http://jaipurcarrentals.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://indianadventuretourpackages.blogspot.com/
http://rajasthantraintourpackage.blogspot.com/
http://jaipurinformationguide.blogspot.com/
http://rajasthanculturaltourpackages.blogspot.com/
http://uttaranchaltourpackages.blogspot.com/
http://luxurytourspackages.blogspot.com/
http://indiahimalayatourtravelpackages.blogspot.com/
http://eastindiatravelpackages.blogspot.com/
http://indiahillstationstravelpackages.blogspot.com/
http://indiatravelpackages.blogspot.com/
http://westindiatourpackages.blogspot.com/
http://lehladakhtourpackages.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://worldtravelsguide.blogspot.com/
http://jaipursilverjewellery.com/
http://www.jaipurhandicrafts.com/
http://dl3.com/link/category/voice
http://dl3.com/link/category/chat
http://dl3.com/link/category/song
http://dl3.com/link
http://www.dl3.com/smiles
http://www.dl3.com/cards
http://games.dl3.com
http://www.chataluae.com
http://www.dl3.com/vb/index.php
http://www.dl3.com/vb
http://www.dl3.com/vb
http://www.dl3.com
http://www.stop10.com
http://topics.ll6.com
http://topics.ll6.com
http://www.stop10.com
http://www.ll6.com/java.shtml
http://dlel.ll6.com/c21.html
http://dlel.ll6.com/c20.html
http://dlel.ll6.com/c19.html
http://dlel.ll6.com/c18.html
http://dlel.ll6.com/c17.html
http://dlel.ll6.com/categories.xml
http://dlel.ll6.com/sitemap.xml
http://dlel.ll6.com/c10.html
http://dlel.ll6.com/c9.html
http://dlel.ll6.com/c8.html
http://dlel.ll6.com/c7.html
http://dlel.ll6.com/c6.html
http://dlel.ll6.com/c5.html
http://dlel.ll6.com/c4.html
http://dlel.ll6.com/c3.html
http://dlel.ll6.com/c2.html
http://dlel.ll6.com/c10.html
http://dlel.ll6.com/c16.html
http://dlel.ll6.com/c15.html
http://dlel.ll6.com/c14.html
http://dlel.ll6.com/c13.html
http://dlel.ll6.com/c12.html
http://dlel.ll6.com/c11.html
http://voice.ll6.com
http://www.ll6.com
http://vb.ll6.com/forumdisplay.php?f=50
http://vb.ll6.com/forumdisplay.php?f=41
http://vb.ll6.com/forumdisplay.php?f=35
http://vb.ll6.com/forumdisplay.php?f=34
http://vb.ll6.com/forumdisplay.php?f=33
http://vb.ll6.com/forumdisplay.php?f=32
http://vb.ll6.com/forumdisplay.php?f=31
http://vb.ll6.com/forumdisplay.php?f=30
http://vb.ll6.com/forumdisplay.php?f=29
http://vb.ll6.com/forumdisplay.php?f=28
http://vb.ll6.com/forumdisplay.php?f=27
http://vb.ll6.com/forumdisplay.php?f=26
http://vb.ll6.com/forumdisplay.php?f=25
http://vb.ll6.com/forumdisplay.php?f=24
http://vb.ll6.com/forumdisplay.php?f=23
http://vb.ll6.com/forumdisplay.php?f=22
http://vb.ll6.com/forumdisplay.php?f=21
http://vb.ll6.com/forumdisplay.php?f=20
http://vb.ll6.com/forumdisplay.php?f=19
http://vb.ll6.com/forumdisplay.php?f=18
http://vb.ll6.com/forumdisplay.php?f=17
http://vb.ll6.com/forumdisplay.php?f=5
http://vb.ll6.com/forumdisplay.php?f=6
http://vb.ll6.com/forumdisplay.php?f=10
http://vb.ll6.com/forumdisplay.php?f=4
http://vb.ll6.com/index.php
http://ll6.com
http://www.alshalah.com
http://www.alshalah.com/chat1420.html
http://www.alshalah.com/music22.html
http://www.alshalah.com/music21.html
http://www.alshalah.com/chat1355.html
http://www.alshalah.com/chat1507.html
http://www.alshalah.com/download7.html
http://www.alshalah.com/download7.html
http://www.alshalah.com/chat1337.html
http://www.alshalah.com/chat100.html
http://www.alshalah.com/music12.html
http://www.alshalah.com/music12.html
http://www.alshalah.com/download5.html
http://www.alshalah.com/music23.html
http://www.alshalah.com/chat1339.html
http://www.alshalah.com/chat103.html
http://www.alshalah.com/music15.html
http://www.alshalah.com/chat1528.html
http://www.alshalah.com/chat1359.html
http://www.alshalah.com/chat1519.html
http://www.alshalah.com/chat1422.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/chat106.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat1166.html
http://www.alshalah.com/vote.php
http://www.alshalah.com/visit.php
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2821.html
http://www.alshalah.com/chat2820.html
http://www.alshalah.com/chat2820.html
http://www.alshalah.com/chat2819.html
http://www.alshalah.com/chat2819.html
http://www.alshalah.com/chat2818.html
http://www.alshalah.com/chat2818.html
http://www.alshalah.com/chat2817.html
http://www.alshalah.com/chat2817.html
http://www.alshalah.com/chat2816.html
http://www.alshalah.com/chat2816.html
http://www.alshalah.com/chat2815.html
http://www.alshalah.com/chat2815.html
http://www.alshalah.com/chat2814.html
http://www.alshalah.com/chat2814.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2812.html
http://www.alshalah.com/chat2812.html
http://www.alshalah.com/chat2813.html
http://www.alshalah.com/chat2811.html
http://www.alshalah.com/chat2811.html
http://www.alshalah.com/chat2810.html
http://www.alshalah.com/chat2810.html
http://www.alshalah.com/chat2809.html
http://www.alshalah.com/chat2809.html
http://www.alshalah.com/chat2808.html
http://www.alshalah.com/chat2808.html
http://www.alshalah.com/chat2807.html
http://www.alshalah.com/chat2807.html
http://www.alshalah.com/chat2806.html
http://www.alshalah.com/chat2806.html
http://www.alshalah.com/chat2805.html
http://www.alshalah.com/chat2804.html
http://www.alshalah.com/chat2803.html
http://www.alshalah.com/chat2803.html
http://www.alshalah.com/chat2802.html
http://www.alshalah.com/voice
http://www.alshalah.com/vb
http://www.alshalah.com/
http://www.alshalah.com/download3.html
http://www.alshalah.com/music6.html
http://www.alshalah.com/music6.html
http://www.alshalah.com/music5.html
http://www.alshalah.com/music5.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/music4.html
http://www.alshalah.com/music3.html
http://www.alshalah.com/music3.html
http://www.alshalah.com/music22.html
http://www.alshalah.com/music21.html
http://www.alshalah.com/music19.html
http://www.alshalah.com/music18.html
http://www.alshalah.com/vb/sex202
http://www.alshalah.com/vb/sex205
http://www.alshalah.com/vb/sitemap
http://www.alshalah.com/vb/sitemap/f-183.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/chat101.html
http://www.alshalah.com/vb/picturet38947.html
http://www.alshalah.com/vb/picturet25902.html
http://www.alshalah.com/chat2801.html
http://www.alshalah.com/chat2800.html
http://www.alshalah.com/chat2799.html
http://www.alshalah.com/download10.html
http://www.alshalah.com/chat259.html
http://www.alshalah.com/vb/picturet939.html
http://www.alshalah.com/vb/picturet7317.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat312.html
http://www.alshalah.com/vb/picturet706.html
http://www.alshalah.com/vb/picturet22974-2.html
http://www.alshalah.com/vb/picturet26805.html
http://www.alshalah.com/chat601.html
http://www.alshalah.com/vb/picturet29167.html
http://www.alshalah.com/vb/picturet21358.html
http://www.alshalah.com/vb/picturet42591.html
http://www.alshalah.com/vb/picturet10141.html
http://www.alshalah.com/chat960.html
http://www.alshalah.com/chat658.html
http://www.alshalah.com/chat102.html
http://www.alshalah.com/chat1166.html
http://www.alshalah.com/vb/picturet34614.html
http://www.alshalah.com/chat2470.html
http://www.alshalah.com/vb/picturet44915.html
http://www.alshalah.com/download5.html
http://www.alshalah.com/chat2408.html
http://www.alshalah.com/chat2408.html
http://www.alshalah.com/vb/picturet24559.html
http://www.alshalah.com/music11.html
http://www.alshalah.com/vb/picturet40695.html
http://www.alshalah.com/vb/picturet1067.html
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.dir.3rabstarz.com/
http://www.up.3rabstarz.com
http://www.roo7e.com
http://www.roo7e.com
http://www.al33ab.com
http://ksacam.com
http://chat.ksacam.com
http://ksacam.info
http://oo2o.com
http://s4cam.com
http://saudi4cam.com				
http://voice.ksacam.com
http://سعودي-كام.oo2o.com
http://سعوديكام.com
http://xn--mgbply5cnrr.com
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.dir.3rabstarz.com/
http://www.up.3rabstarz.com
http://www.3rabstarz.com/vb/forumdisplay.php?f=5
http://www.3rabstarz.com/vb/forumdisplay.php?f=116
http://www.3rabstarz.com/vb/forumdisplay.php?f=66
http://www.3rabstarz.com/vb/forumdisplay.php?f=78
http://www.3rabstarz.com/vb/forumdisplay.php?f=147
http://www.3rabstarz.com/vb/forumdisplay.php?f=2
http://www.3rabstarz.com/vb/forumdisplay.php?f=31
http://www.3rabstarz.com/vb/forumdisplay.php?f=136
http://www.3rabstarz.com/vb/forumdisplay.php?f=34
http://www.3rabstarz.com/vb/forumdisplay.php?f=89
http://www.3rabstarz.com/vb/forumdisplay.php?f=26
http://www.3rabstarz.com/vb/forumdisplay.php?f=72
http://www.3rabstarz.com/vb/forumdisplay.php?f=73
http://www.3rabstarz.com/vb/forumdisplay.php?f=149
http://www.3rabstarz.com/vb/forumdisplay.php?f=150
http://www.3rabstarz.com/vb/forumdisplay.php?f=151
http://www.3rabstarz.com/vb/forumdisplay.php?f=152
http://www.3rabstarz.com/vb/forumdisplay.php?f=67
http://www.3rabstarz.com/vb/forumdisplay.php?f=3
http://www.3rabstarz.com/vb/forumdisplay.php?f=37
http://www.3rabstarz.com/vb/forumdisplay.php?f=115
http://www.3rabstarz.com/vb/forumdisplay.php?f=76
http://www.3rabstarz.com/vb/forumdisplay.php?f=77
http://www.3rabstarz.com/vb/forumdisplay.php?f=36
http://www.3rabstarz.com/vb/forumdisplay.php?f=153
http://www.3rabstarz.com/vb/forumdisplay.php?f=122
http://www.3rabstarz.com/vb/forumdisplay.php?f=118
http://www.3rabstarz.com/vb/forumdisplay.php?f=119
http://www.3rabstarz.com/vb/forumdisplay.php?f=120
http://www.3rabstarz.com/vb/forumdisplay.php?f=121
http://www.3rabstarz.com/vb/forumdisplay.php?f=35
http://www.3rabstarz.com/vb/forumdisplay.php?f=65
http://www.3rabstarz.com/vb/forumdisplay.php?f=7
http://www.3rabstarz.com/vb/forumdisplay.php?f=9
http://www.3rabstarz.com/vb/forumdisplay.php?f=11
http://www.3rabstarz.com/vb/forumdisplay.php?f=142
http://www.3rabstarz.com/vb/forumdisplay.php?f=143
http://www.3rabstarz.com/vb/forumdisplay.php?f=146
http://www.3rabstarz.com/vb/forumdisplay.php?f=140
http://www.3rabstarz.com/vb/forumdisplay.php?f=137
http://www.3rabstarz.com/vb/forumdisplay.php?f=114
http://www.3rabstarz.com/vb/forumdisplay.php?f=117
http://www.3rabstarz.com/vb/forumdisplay.php?f=113
http://www.3rabstarz.com/vb/forumdisplay.php?f=51
http://www.3rabstarz.com/vb/forumdisplay.php?f=84
http://www.3rabstarz.com/vb/forumdisplay.php?f=138
http://www.3rabstarz.com/vb/forumdisplay.php?f=139
http://www.3rabstarz.com/vb/forumdisplay.php?f=15
http://www.3rabstarz.com/vb/forumdisplay.php?f=130
http://www.3rabstarz.com/vb/forumdisplay.php?f=97
http://www.3rabstarz.com/vb/forumdisplay.php?f=102
http://www.3rabstarz.com/vb/forumdisplay.php?f=101
http://www.3rabstarz.com/vb/forumdisplay.php?f=104
http://www.3rabstarz.com/vb/forumdisplay.php?f=131
http://www.3rabstarz.com/vb/forumdisplay.php?f=103
http://www.3rabstarz.com/vb/forumdisplay.php?f=99
http://www.3rabstarz.com/vb/forumdisplay.php?f=59
http://www.3rabstarz.com/vb/forumdisplay.php?f=60
http://www.3rabstarz.com/vb/forumdisplay.php?f=39
http://www.3rabstarz.com/vb/forumdisplay.php?f=40
http://www.3rabstarz.com/vb/forumdisplay.php?f=42
http://www.3rabstarz.com/vb/forumdisplay.php?f=4
http://www.3rabstarz.com/vb/forumdisplay.php?f=1
http://www.3rabstarz.com/vb/forumdisplay.php?f=88
http://www.3rabstarz.com/vb/forumdisplay.php?f=148
http://www.3rabstarz.com/vb/forumdisplay.php?f=62
http://www.3rabstarz.com/vb/forumdisplay.php?f=63
http://www.3rabstarz.com/vb/forumdisplay.php?f=64
http://www.3rabstarz.com/vb/forumdisplay.php?f=6
http://www.3rabstarz.com/vb/forumdisplay.php?f=12
http://www.3rabstarz.com/vb/forumdisplay.php?f=96
http://www.3rabstarz.com/vb/forumdisplay.php?f=58
http://www.3rabstarz.com/vb/forumdisplay.php?f=38