开发者

using JQuery.browser to choose CSS based on layout engine

I don't see why this doesn't work. I assume that for some really lame reason an if statement might not be able to validate a string of text but that would make me very angry at who's writing these scripting languages.

//I don't want to know the browser. I want to know the layout engine the user is using.
if($.layout.name == "webkit"){$("#debug").html("your browser uses webkit");}

//I eventually want to do this
if($.layout.name == "webkit"){
  document.write('<link rel="stylesheet" href="/css/webkit-name-v006.css" type="text/css" media="screen">');
}

I looked all over for documentation on how to use the jquery.browser plugin开发者_开发技巧 but they only give info for detecting the specific browser name they do not give examples for checking for layout engine.

//this is the closest working example I found online
$.browser.safari = /safari/.test(navigator.userAgent.toLowerCase()); if ($.browser.safari) { 
 document.write('<link rel="stylesheet" href="http://domain.tld/css/safari.css" type="text/css" media="screen">'); }

I need to write a script that chooses the CSS file based on browser layout, not version.

I don't wanna hear any hype about feature detection. I have been there and seen it's error. Just wanna make this work.

Thanks.


Try this:

$(document).ready(function()
{
    if($.browser.webkit){
        $("head").append(
            $("<link />").attr({
                rel:  "stylesheet",
                type: "text/css",
                href: "file.css"
            })
        );
    }
});


//FOUND THE ANSWER I was putting the code in an if statement string and for got to say "else if"

Here is the working code

//WEBKIT    SAFARI CHROME     CSS
if($.layout.name == 'webkit'){$("#debug").html("your browser uses webkit");}
//GECKO     FIREFOX MOZILLA   CSS
else if($.layout.name == 'gecko'){$("#debug").html("your browser uses gecko");}
//TRIDENT   IE                CSS
else if($.layout.name == "trident"){$("#debug").html("your browser uses trident");}
//PRESTO    OPERAH            CSS
else if($.layout.name == "presto"){$("#debug").html("your browser uses presto");}
//KNOW ONE KNOWS
else{$("#debug").html("your browser is unrecognized");}
//IOS       IPHONE            CSS
//ANDROID   GALAXY            CSS
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜