简体   繁体   English

如何在Google Closure编译器中检测用户代理或浏览器?

[英]How can i detect user agent or browser in google closure compiler?

My Complier file is like that 我的Complier文件就是这样

cd /d %~dp0
java -jar ../../../../file/css-compiler.jar --pretty-print ^
--allowed-unrecognized-property -khtml-opacity ^
    ../source/abc.gss ^
    > ../abc.css
pause

when i am adding following line in order to detect IE Compiler giving error 当我添加以下行以检测IE编译器给出错误时

<!--[if IE]>
.vidizmo-widget .result-summary {width:0px;}
<![endif]-->

then I write following line 然后我写以下行

@if (BROWSER_IE) {
.vidizmo-widget .result-summary {width:0px;}
}@else{
.vidizmo-widget .result-summary {width:30%;}
}

it doesn't generate error but i didn't find any impact on IE. 它不会产生错误,但是我没有发现对IE的任何影响。

how can i detect browser using google css compiler ? 如何使用Google CSS编译器检测浏览器?

Yes, your second approach is correct 是的,您的第二种方法是正确的

@if (BROWSER_IE) {
  .vidizmo-widget .result-summary {width:0px;}
}@else{
  .vidizmo-widget .result-summary {width:30%;}
}

Then you need to compile the closure template (gss) for every browser (more precisely: for every flag) you defined: 然后,您需要为您定义的每个浏览器(更精确地说:对于每个标志)编译闭包模板(gss):

java -jar closure-stylesheets.jar example.gss > example.css
java -jar closure-stylesheets.jar --define BROWSER_IE example.gss > example.ie.css
java -jar closure-stylesheets.jar --define BROWSER_FF2 example.gss > example.ff2.css
…

Then, you need to load the appropriate css; 然后,您需要加载适当的CSS; and this is easy: 这很容易:

  • either with JavScript 要么用JavScript
  • or with a server-side serving based on User-Agent 或基于User-Agent的服务器端服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM