Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于浏览器的可选样式表_Javascript_Css_Cross Browser - Fatal编程技术网

Javascript 基于浏览器的可选样式表

Javascript 基于浏览器的可选样式表,javascript,css,cross-browser,Javascript,Css,Cross Browser,任何人都知道是否有可能让javascript计算出页面在哪个浏览器中使用,并相应地加载样式表。理想情况下,我希望每个浏览器都有一个不同的sytlesheet,css媒体查询现在只进行到这一步 是的,这是可能的。您可以通过“”对象检测浏览器,但我想最好的办法是同时使用jQuery for和。使用内置导航器对象的浏览器检测示例(源:): txt=“浏览器代码名:”+navigator.appCodeName+“”; txt+=“浏览器名称:”+navigator.appName+“”; txt+=“

任何人都知道是否有可能让javascript计算出页面在哪个浏览器中使用,并相应地加载样式表。理想情况下,我希望每个浏览器都有一个不同的sytlesheet,css媒体查询现在只进行到这一步

是的,这是可能的。您可以通过“”对象检测浏览器,但我想最好的办法是同时使用jQuery for和。

使用内置导航器对象的浏览器检测示例(源:):

txt=“浏览器代码名:”+navigator.appCodeName+“

”; txt+=“浏览器名称:”+navigator.appName+“

”; txt+=“浏览器版本:”+navigator.appVersion+“

”; txt+=“Cookies已启用:”+navigator.cookieEnabled+“

”; txt+=“平台:“+navigator.Platform+”

”; txt+=“用户代理标题:“+navigator.userAgent+”

”; document.getElementById(“示例”).innerHTML=txt; 查看此内容,了解如何使用JavaScript加载CSS:

这也可能有效(来源:):

函数includecs(p_文件){ var v_css=document.createElement('link'); v_css.rel='样式表' v_css.type='text/css'; v_css.href=p_文件; document.getElementsByTagName('head')[0].appendChild(v_css); }
如果你只想点击IE版本,有条件的评论效果很好

如果要针对浏览器实现这些功能,请使用Modernizer:

如果没有上述任何一项,则应查看浏览器检测:

<div id="example"></div> <script type="text/javascript"> txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>"; txt+= "<p>Browser Name: " + navigator.appName + "</p>"; txt+= "<p>Browser Version: " + navigator.appVersion + "</p>"; txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>"; txt+= "<p>Platform: " + navigator.platform + "</p>"; txt+= "<p>User-agent header: " + navigator.userAgent + "</p>"; document.getElementById("example").innerHTML=txt; </script> function includeCSS(p_file) { var v_css = document.createElement('link'); v_css.rel = 'stylesheet' v_css.type = 'text/css'; v_css.href = p_file; document.getElementsByTagName('head')[0].appendChild(v_css); }