6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iframe

6
Last updated at Posted at 2014-05-24

iframeを複数利用する方法

IEでは複数iframeを表示できたが、なぜかfirefoxやchromeでは1つ目のiframeしか表示されない。

回避策
<!--[if IE]>
<iframe src="〜" width="250" height="170"></iframe>
<![endif]-->

<!--[if !IE]>
<object type="text/html" data="〜" width="250" height="170"></object>
<![endif]-->

chrome35のバージョンアップにともなうiframeの動作変更(?)

<iframe name="iframe1">
</iframe>

この領域に以下で中身を替えていたが、chromeがバージョンアップにともない
以下書き方はできなくなった。

以下は動かなくなった
<script>
iframe1.location.href = "/url1/index.html";
以下は動く
<script>
iframe1.src = "/url1/index.html";

参考
firefoxでiframeをlocation.hrefしたい - Gpso.info 開発ブログ

iframeのinnerHTML取得方法

IEでは以下のように取得できていたが、firefoxでは取得できないことがわかった。

以下はIE以外には対応していない
form1.contents.value = frames.frame1.document.body.innerHTML;
修正版
function getIframeInnerHTML() {
	var form1 = document.frm1;
	if (typeof(frames.frame1.document) !== "undefined") {
		// IE
		return frames.frame1.document.body.innerHTML;
	} else {
		// firefoxなど
		var x = document.getElementById("frame1");
		var y = (x.contentWindow || x.contentDocument);
		if (y.document) {
			y = y.document;
		}
		return y.body.innerHTML;
	}
}
form1.contents.value = getIframeInnerHTML();
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?