#1
  1. di50rd3R
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    portugal
    Posts
    36
    Rep Power
    14

    Arrow js for css browser independent help


    im using this script to use diferent css files
    depending on the users browser type:

    <head>
    <script language="JavaScript" src="css.js"></script>
    <head/>

    css.js file

    <begin>
    <!--
    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt
    (navigator.appVersion)>= 4 )) {
    document.write('<link rel="stylesheet" type="text/css"
    href="ie45.css">')}
    else {
    if (navigator.appName == "Netscape"){
    if (parseInt(navigator.appVersion)>= 5 ){
    document.write('<link rel="stylesheet" type="text/css"
    href="ns6.css">')}
    else {
    document.write('<link rel="stylesheet" type="text/css"
    href="ns4.css">')}
    }
    else {
    document.write('<link rel="stylesheet" type="text/css"
    href="default.css">')}
    }
    //-->
    <end>

    but it doesnt work at all , and i would like to make a
    new one with opera support .
    anyone know if there is something wrong with the code ?
    ive desativated the firewall to test it .
    --==::di50rd3R::==--

    ExplicitPunk.U4L.com

    --==::di50rd3R::==--
  2. #2
  3. No Profile Picture
    Beelzebub
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    The nether regions...ok, San Diego
    Posts
    164
    Rep Power
    14
    Here's how I would code that...
    Code:
    if (document.getElementById && !document.all) { 
    document.write('<link rel="stylesheet" type="text/css" href="ns6.css">')
    } else if (document.all) { 
    document.write('<link rel="stylesheet" type="text/css" href="ie45.css">')
    } else if (document.layers) { 
    document.write('<link rel="stylesheet" type="text/css" href="ns4.css">') 
    } else { 
    document.write('<link rel="stylesheet" type="text/css" href="default.css">') 
    }
    also...<head/> should be </head>
  4. #3
  5. di50rd3R
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    portugal
    Posts
    36
    Rep Power
    14

    Arrow thanks , just 1 ?


    do u know how to add a new function for opera browsers
    and does the ie part support 4 and 5 and 6 vertions
    --==::di50rd3R::==--

    ExplicitPunk.U4L.com

    --==::di50rd3R::==--
  6. #4
  7. No Profile Picture
    Beelzebub
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    The nether regions...ok, San Diego
    Posts
    164
    Rep Power
    14
    write yourself a test function to display the navigator.userAgent, etc, open it in Opera and see what you can test for.

    yes...document.all covers ie4-6
  8. #5
  9. di50rd3R
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    portugal
    Posts
    36
    Rep Power
    14

    Arrow sorry if im a javascript dummy


    must i add this function


    else if (navigator.userAgent) {
    document.write('<link rel="stylesheet" type="text/css" href="op.css">')
    }
    --==::di50rd3R::==--

    ExplicitPunk.U4L.com

    --==::di50rd3R::==--
  10. #6
  11. No Profile Picture
    Beelzebub
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    The nether regions...ok, San Diego
    Posts
    164
    Rep Power
    14
    No...(navigator.userAgent) will always be true. I downloaded Opera and tested some things. It understands document.getElementById and document.all, so it acts like IE. I have no idea how CSS might work differently, you might just test your IE css in opera and see how it looks. If you just have to use a different file...
    Code:
    var agent = "" + navigator.userAgent;
    if (agent.indexOf("Opera") != -1 {
    document.write('<link rel="stylesheet" type="text/css" href="op.css">');
    } else if (document.getElementById && !document.all) { 
    document.write('<link rel="stylesheet" type="text/css" href="ns6.css">');
    } else if (document.all) { 
    document.write('<link rel="stylesheet" type="text/css" href="ie45.css">');
    } else if (document.layers) { 
    document.write('<link rel="stylesheet" type="text/css" href="ns4.css">');
    } else { 
    document.write('<link rel="stylesheet" type="text/css" href="default.css">');
    }
  12. #7
  13. di50rd3R
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    portugal
    Posts
    36
    Rep Power
    14

    Thumbs up thanks


    )
    --==::di50rd3R::==--

    ExplicitPunk.U4L.com

    --==::di50rd3R::==--

IMN logo majestic logo threadwatch logo seochat tools logo