- 共通コンテンツのSEO対策で実装
- すべてのiframeを対象にせず、iframe1のidがあるiframeのみ反映させる
もくじ
html
<iframe src="読み込み先パス" frameborder="0" width="100%" scrolling="no" id="iframe1"></iframe>
Widthは100%で高さはjQueryから取得する
jQuery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
JS
<script>
var height;
var scrollHeight;
jQuery(function($){
$('#iframe1').load(function(){
if (typeof $(this).attr('height') == 'undefined') {
$(this).height(this.contentWindow.document.documentElement.scrollHeight);
}
});
</script>
footer.phpにでも記述するのが良いでしょう
iframe挿入時の注意
- <a href=”URL”>タグのリンクにはtarget=”_blank”を加えること
<a href=”URL” target=”_blank”>
これをしないとフィッシングとしてブラウザでブロックされてリンクが押せない

