Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer Help with Javascript

    Hi all

    I am a n00b to this site and JavaScript and thought this would work but for some reason I think it needs a source within the <body></body> otherwise there is nothing to tell the script to work or am I completely barking up the wrong tree...

    What I'm after is Microsoft and Netscape, Mozilla, Firefox and so on to detect the browser the user is using when viewing the site, therefore showing the correct CSS file for the correct browser. Neat yeah...? But when I view the page none of the CSS will work...

    Any aides please...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Under Development - Coming Soon</title>
    <script type="text/javascript" language="javascript">
    <!-- 
    if (navigator.appName == 'Microsoft 
    Internet Explorer') {
    		document.write('<link rel="stylesheet" type="text/css" href="images/blue/style.css">')
    }
    else {
    		document.write('You are running either Mozilla, Firefox or Netscape?')
    	}
    }
    // -->
    </script>
    </head>
    
    <body background="images/blue/background.gif">
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    Hello, welcome to the forums. You might want to take another look at the posting guidelines; "help with Javascript" isn't really a helpful title in a javascript forum.

    I'm a complete JS idiot, but you can achieve something very similar using IE's conditional comments:
    Code:
    <link rel="stylesheet" media="screen" href="css/style.css" />     <-- this stylesheet is read by all browsers, including nice, standards compliant ones
    
    <!--[if IE]>     <-- this feeds a stylesheet specifically to Internet Explorer, so you can serve all your CSS hacks to only IE
    	<link rel="stylesheet" media="screen" href="css/iestyle.css" />
    <![endif]-->
    Maybe this is an alternative?

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I done it...


    It's working...

    it was because I put a --> Microsoft

    Its should look like this instead... works a treat
    Code:
    <script type="text/javascript" language="javascript">
    <!-- 
    if (navigator.appName == 'Microsoft Internet Explorer') {
    		document.write('<link rel="stylesheet" type="text/css" href="images/blue/style.css">')
    }
    else {
    		document.write('You are running either Mozilla, Firefox or Netscape?')
    	}
    // -->
    </script>
    and now it brings up the message for Mozilla... All I have to do now is write a CSS file to be compatible with Mozilla, Firefox, Netscape, Opera... man that will be some work...

    Thanks
    Last edited by Krudo; 02-03-2005 at 11:48 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •