webページの一部で、iframeを使用して別ページを埋め込む。
このとき、スクロールを表示せず、埋め込んでない風に(いかにもページの一部ですよ風に)表示する。
をしたいと思ってます。
(分岐が多いフォームなので、1ファイルでやらずに、ファイルを分けて、選択によって表示ファイルを変えようとしてます。)
いろいろ探して、以下のページにたどりついたのですが、
手元のJavaScriptのファイルが、外部ファイルで、関数使ってます。
http://dtp.jdash.info/archives/jQuery_iframe_auto_height_script
(function(window, $){ $(window).on("load",function(){ $('iframe.autoHeight').each(function(){ var D = $(this).get(0).contentWindow.document; /* console.log( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); */ var innerHeight = Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); $(this).css('height', innerHeight + 'px'); }); }); })(window, jQuery);
上記を
function hogehoge(){
}
という形に書き換えてみたのですが、全く動く気配がなく、
スクロールバーが出てしまいます。
書き方が間違えてるのでしょうか。。。
function autoHeight(){ (function(window, $){ $(window).on("load",function(){ $('iframe.autoHeight').each(function(){ var D = $(this).get(0).contentWindow.document; var innerHeight = Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); $(this).css('height', innerHeight + 'px'); }); }); })(window, jQuery); }
回答2件
あなたの回答
tips
プレビュー