I want to add dynamic css in my html page, I made a function using navigator function if the browser is mozilla then function will add mozilla css otherwise it should add IE css but somehow I am unable to make it working.
<head>
<script type="text/javascript">
var cs;
function nav() {
var txt= navigator.appCodeName;
if(txt=='mozilla') {
cs= mozilla;
}
else{
cs= ie;
}}
</script>
</head>
<body onload="nav ()">
<p id="cab"></p>
</body>
</html>
You really should use conditional IE comments for this, not JavaScript. This is for many reasons including:
The JavaScript you’ve written has a couple of issues:
If you really want to do it with JavaScript you could remove the link tag from your page’s head section and try a function something like this (not tested):