-
dynamically load css into a web page?
Is it possible to do a browser detection and instead of redirecting to a compatible page have a compatible css document load?
I'm rebuilding my website right now. I have three style sheets , one for ie7, one for Firefox, and one for ie6 and older - the same pages with the same info, the only thing that changes from browser to browser are the style sheets.
It would be real nice if I didn't have to make three different web sites just for it to be seen on all browsers.
to the moderators; Not trying to do over kill but I'm also going to post this in the css forum just in case they know something the php guys don't
-
-
This is really old - back from when CSS support in the browsers is not as good as it is today. I don't use this method anymore, but here it is...
In the head of your document call the javascript file:
<script language="javascript" src="j/rc.js"></script>
In this case the javascript would reside in a folder "j" and be named "rc.js"
====
And the javascript (change the browser detection to whatever you need, like I said, this is very old):
var name = navigator.appName.toLowerCase();
var ver = navigator.appVersion.toLowerCase();
if(name == "microsoft internet explorer" && ver >="4")
{
//IE, version 4 or greater
if(ver.indexOf("mac") != -1)
{
//Macintosh
document.write('<link rel="stylesheet" href="c/gmac.css" TYPE="text/css">');
}
else
{
//Windows
document.write('<link rel="stylesheet" href="c/g.css" TYPE="text/css">');
}
}
else if (document.getElementById)
{
//Navigator, version 6 or greater
if(ver.indexOf("mac") != -1)
{
//Macintosh
document.write('<link rel="stylesheet" href="c/g6mac.css" TYPE="text/css">');
}
else
{
//Windows
document.write('<link rel="stylesheet" href="c/g6.css" TYPE="text/css">');
}
}
else if(name == "netscape" && ver >="4")
{
//Navigator, version 4 or greater but less than Version 6 which is detected above getElementById
if(ver.indexOf("mac") != -1)
{
//Macintosh
document.write('<link rel="stylesheet" href="c/g4mac.css" TYPE="text/css">');
}
else
{
//Windows
document.write('<link rel="stylesheet" href="c/g4.css" TYPE="text/css">');
}
}
else if(name == "opera" && ver >="4")
{
//Opera, version 4 or greater
if(ver.indexOf("mac") != -1)
{
//Macintosh
document.write('<link rel="stylesheet" href="c/g6mac.css" TYPE="text/css">');
}
else
{
//Windows
document.write('<link rel="stylesheet" href="c/g6.css" TYPE="text/css">');
}
}
====
Cheers!
--
Jim S
Jacksonville Web Design
http://tentonweb.com/
-
-
thanks, I hadn't realized I had a reply...was expecting an email notification. Anyway, I appreciate your help. I've been attempting to do this through php. As it stands I know how to get the browser type, just havn't figured out how to load the css. If you have any info Id love to hear it. Otherwise, if all else fails I'll be using the code above.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks