Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default Javascript Browser Detection

    To add a css file for opera and safari, I'm using this code I found:
    Code:
    function isSaf() {
        return = (document.childNodes && !document.all && !navigator.taintEnabled && !navigator.accentColorName) ? true : false;
    }
      
    function isOp() {
        return (window.opera) ? true : false;
    }
    
    function loadPatches(dir) {
        if (document.getElementsByTagName() && document.createElement()) {
            var head = document.getElementsByTagName("head")[0];
             if (head) {
                var css = new Array();
                if (isSaf()) {
                    css.push("saf.css");
                } else if (isOp()) {
                    css.push("opera.css");
                }
     
                if (css.length) {
                    var link = document.createElement("link");
                    link.setAttribute("rel", "stylesheet");
                    link.setAttribute("type", "text/css");
                    link.setAttribute("media", "screen, projection");
                    for (var i = 0; i < css.length; i++) {
                        var tag = link.cloneNode(true);
                        tag.setAttribute("href", dir + css[0]);
                        head.appendChild(tag);
                    }
                }
            }
        }
    }
    $(document).ready(function() {
        loadPatches('css/')
    });
    With a bit of editing I got it working, but for some strange reason, It's not liking the opera detection, safari detection works, but opera doesn't, I've used firebug to detect whether it has been written to the document and it hasn't. Any ideas?
    How could this hapen to meeeeeeeeeeeeeee?lol.

  2. #2
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Opera is a fairly new browser, your code must be ancient.

  3. #3
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    The validation is very un-error-prone, it's just "window.opera"...
    How could this hapen to meeeeeeeeeeeeeee?lol.

Posting Permissions

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