SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Chrome Javascript Conditional Comment

    I'm using this script to load CSS for just Chrome browsers, but for some reason Firefox and Safari are picking up the styles I'm using only for chrome.css.

    Is there something wrong with this?

    Code:
    		<script type="text/javascript">
        if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1);
        document.write('<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/chrome.css">');
        </script>

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Code:
    		<script type="text/javascript">
        if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1);
    Here's your problem ........................ ^
        document.write('<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/chrome.css">');
        </script>
    Mistakes like this -- that are small, yet hard to spot -- are why almost every C-style language style guide recommends that you always use braces, even if the block is only one statement long.

    Code:
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
        document.write('<link rel="stylesheet" type="text/css" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/chrome.css">');
    }
    "First make it work. Then make it better."

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Beauty! Thank you, Jeff Mott!


Tags for this Thread

Bookmarks

Posting Permissions

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