SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,293
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    css on/available or not detection?

    is it possible to use js to see if css is on or not in the user's browser?

    i want to mark a point on a map (the map being a single png image), and i'll probably use css layers and positioning to get the dot and label image into the right place over the map. if css isn't on then i don't want to put the mark on the page at all as it'll appear in an odd place (not even on the map) and be meaningless.

    thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    I think the easiest way is to use jquery's selectors

    $("link[href=/path/to/stylesheet.css]").length > 0

    But you have to include a 25 kb library..

    other way would be using getElementsByTagName and looping through them to find out if any has link=/path/to/stylesheet.css

    jquery just makes it easier

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could do something like this, I suppose:
    Code HTML4Strict:
    <div id="detect" style="width:2px"></div>
    Code JavaScript:
    if (document.getElementById("detect").offsetWidth === 2) {
        ...
    }
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha I thought you want to check for particular file

    but 99&#37; guys with css off has also javascript off I suppose..

  5. #5
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,293
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks. i suppose the best thing would be to add the marker/label entirely by css. that would be a pseudo element content thing but, i think, a number of browsers which can do css can't do content. hmm, maybe adding the image by normal html but specifying a 1px by 1px size for it so it'd be invisible, then resizing and positioning it by css might work. if no css image remains invisible, if css it gets positioned and sized appropriately. yes that seems quite good (without having thought about it too much yet).

    thanks.


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
  •