Forums

browser detection then swapping css.... (5 posts)

  1. mentaleruptions
    Member
    Posted 3 years ago #

    Im looking for a way to change the css file thats loaded depending on the browser the blog is viewed from. Ive searched the net and these forums and found a few ways but nothing seams to work.

    This is what i currently have and it doesnt do what it should:

    <link rel="stylesheet" href="http://mywebsite.com/wp-content/themes/mytheme/style.css" type="text/css" media="screen" />
    <!--[if IE 6]>
    <link rel="stylesheet" href="http://mywebsite.com/wp-content/themes/mytheme/iestyle.css" type="text/css" media="screen" />
    <![endif]-->

    For some reason IE doesnt bypass the first link to the style.css file and just loads it. However if i remove the first link to style.css then IE loads the iestyle.css and firefox doesnt load any css file.

    Anyone got any clues what im doing wrong with this code ??

    Thanks,

    Tom

  2. petit
    Member
    Posted 3 years ago #

    I haven't tested it my self, but maybe this is the answer:
    Browser Dependent Cascading Style Sheets (CSS) in PHP

  3. petit
    Member
    Posted 3 years ago #

    ....?

  4. mentaleruptions
    Member
    Posted 3 years ago #

    Thanks petit,

    Ive not had chance to test it but will let you know once i do.

    Tom

  5. mentaleruptions
    Member
    Posted 3 years ago #

    <?php

    $browser = get_browser();

    $css_file = ($browser->browser == 'Firefox' && $browser->version == 1.0) ? 'http://mywebsite.com/wp-content/themes/mytheme/style.css' : 'http://mywebsite.com/wp-content/themes/mytheme/iestyle.css';

    echo '<link rel="stylesheet" type="text/css" href="' . $css_file . '" />';

    ?>

    Well ive installed the browscap.ini and have set the code up like above to detect browser. However i can only get one or the other to show up but not both. Ive tried it detecting internet explorer and firefox but neither seam to work.

    Tom

  6. petit
    Member
    Posted 3 years ago #

    If you are using Firefox 1.5, the above code should give you "iestyle.css", and I suppose you don't use the old 1.0. I'm not yet a PHP savvy guy, so I don't know about browscap.ini and its use. Maybe someone else can jump in here.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.