【发布时间】:2010-12-14 17:28:21
【问题描述】:
我找到了以下 javascript 代码来获取浏览器窗口大小,效果很好!
<script type="text/javascript">
<!--
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
// older versions of IE
else
{
viewportwidth = document.body.clientWidth,
viewportheight = document.body.clientHeight
}
document.write('<p>Your viewport width is <b>'+viewportwidth+'x'+viewportheight+'</b>.</p>');
//-->
</script>
现在我需要将它传递给 Grails 控制器,以便我可以根据屏幕大小调整图像大小。
使用:
<div align="center" valign="middle">
<img src="${createLink(controller:'chart', action:'buildChart')}" />
</div>
我该怎么做? 提前致谢!
【问题讨论】:
-
你考虑过使用 jQuery 吗?据我所知,
.width方法在所有浏览器上都能获得正确的宽度。
标签: javascript image grails window size