xhtmlにするとJavaScriptがIE以外で動作しない


xhtmlにするとJavaScriptがIE以外で動作しない

htmlで作成したページで、下記のスクリプトを使用していた。

<iframe src="menu.html" width="190" marginheight="0" frameborder="no" scrolling="no" onload="if( this.contentWindow.document.body.scrollHeight < ( document.body.scrollHeight - 200 ) ){ this.style.height= document.body.scrollHeight - 200; }else{ this.style.height=this.contentWindow.document.body.scrollHeight; }">
</iframe>

これをxhtmlにするとIEでは動作したが、それ以外のブラウザでは動作しなかった。

ネットで調べると下記の記事を見つけた。

xhtmlにするとIE以外で動作しない

「単位(px)をつけないとXHTMLでは動きません。」とあったので、下記のようにpxをつけてやると動作した。

<iframe src="menu.html" width="190" marginheight="0" frameborder="no" scrolling="no" onload="if( this.contentWindow.document.body.scrollHeight < ( document.body.scrollHeight - 200 ) ){ this.style.height= (document.body.scrollHeight - 200)+ 'px'; }else{ this.style.height=(this.contentWindow.document.body.scrollHeight)+ 'px'; }">
</iframe>
  • このエントリーをはてなブックマークに追加

コメントをどうぞ

メールアドレスが公開されることはありません。