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 Coder
    Join Date
    Nov 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem linking HTML to 2 Different CSS Style Sheets

    I am having difficulty finding in the forum information that relates specifically to what I am trying to attempt.

    I have two CSS style sheets created. One obviously works cause everything is being styled and the other one isnt. I am not sure why this is or wondering if I missed something or typed something incorrectly.

    One style sheet is for IE and the other one is for firefox.

    This is the code I put in my JavaScript .js file

    function pickCSS() {
    var browsername = navigator.appName;
    if(browsername=="Microsoft Internet Explorer") {
    document.write("<link rel='stylesheet' href='explorercss.css' type='text/css'>");
    }
    else if(browsername=="Mozilla") {
    document.write("<link rel='stylesheet' href='mycss.css' type='text/css'>");
    }
    }

    This is the code at the top of my HTML file

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Msource</title>
    <link href="mycss.css" rel="stylesheet" type="text/css" />
    <link href="explorercss.css" rel="stylesheet" type="text/css" />
    <script language="JavaScript" src="javascript1.js"></script>
    <script type="text/JavaScript">
    <!--
    pickCSS();
    //-->
    </script>
    </head>

    Any assisstance would be greatly appreciated.

  • #2
    New Coder
    Join Date
    Nov 2006
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    forget it... Once I put Netscape instead of Mozilla it worked fine.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Using javascript to configure user styles is a bad idea. JS can be disabled. You are better off using conditional comments.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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