ブラウザのウィンドウサイズを取得するために、次のjavascriptコードが見つかりました。Grailsコントローラにjavascriptのvar値を渡す方法は?
<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'](http://api.jquery.com/width/)メソッドはすべてのブラウザで正しい幅を取得します。 – treeface