简体   繁体   中英

Grails GSP Screen Width

I need to check the screen size to change a component. Without knowing the best way, i try use javascript in

 <g:if test="${javascript($(window).width() > 768)}"> //COMPONENT </g:if> <g:else> //OTHER COMPONENT </g:else> 

Anyone can help me saying the best way to resolve this?

Thanks

Without knowing that COMPONENT is in your example it's difficult to offer a solid solution.

However, the major issue you are facing is that you are trying to mix server-side and client-side evaluation which you can't do. GSP is evaluated at the server level and doesn't have access to the browser's DOM to get things such as window.width .

One possible solution is to submit the window.width with the request to the GSP as a request variable so that you can evaluate that using the GSP.

@Joshua is right, you are mixing and matching client and server side code. You could use a plugin https://github.com/mathifonseca/grails-browser-detection which is a nice wrapper around the httprequest so you can check if you are communicating with a desktop or mobile browser. But normally this would be done using stylesheet (@see: http://www.w3schools.com/html/html_responsive.asp )

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