Trying to get main javascript detection working
sagaticus
Status: New User - Welcome
Joined: 22 Aug 2007
Posts: 2
Reply Quote
This is just what I was looking for, script seems perfect... but I'm still trying to get it working. Here is what I have (it's not pulling in the css)

:: Code ::
 <script type="text/javascript" src="browser_detection.js"></script>
 
<script language="JavaScript">
function browser_css( ) {
   d = document;
   if ( saf ) {
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_safari.css" />');
   }
   else if ( document.layers ){
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_moz.css" />');
   }
   else if ( ie6 ){
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_ie6.css" />');
   }
   else if ( ie7 ){
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_ie7.css" />');
   }
   else if ( moz && ( nu < 1 ) ){
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_moz.css" />');
   }
   else {
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_moz.css" />');
   }
}
</script>


What am I doing wrong? I have four css files created one with a different color attribute based on the browser. Just testing here, but keep failing. Thanks...
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
to debug issues, you need to make sure the stuff is loading and running.

So in the library file, place this line: alert('library file running');

and in the function you are calling, place another alert: alert('function running');

After this, you'll realize that the function is not running because you didn't call it.

Declaring a function makes it available for the page to use, but to use it, you have to do this:

browser_css( );

after the last bracket of the function, like so:

:: Code ::
else {
      d.write('<link rel = "stylesheet" type = "text\/css" href = "browser_moz.css" />');
   }
}

browser_css( );
</script>

Back to top
sagaticus
Status: New User - Welcome
Joined: 22 Aug 2007
Posts: 2
Reply Quote
Thanks! this now works perfectly for IE7, ffox, safari, and IE6.

Script is very well written, thank you!
Back to top
Display posts from previous:   

All times are GMT - 8 Hours