简体   繁体   中英

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

My Complier file is like that

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

<!--[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.

how can i detect browser using google css compiler ?

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:

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; and this is easy:

  • either with JavScript
  • or with a server-side serving based on User-Agent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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