12/02/18 02:58:45.96 POt9ATxZ
【環境】OS:windows7 professional ブラウザ:Firefox11.0/IE8.0.7610.17514/Google Chrome17.0.963.56m
【期待する結果】どのブラウザでもiframe内のHTMLにあるタグの内容を読み取りたい。
【サンプルコード】
[a.html]
<html><head>
<!-- saved from url=(0013)about:internet -->
<meta heep-equiv="Content-Script-Type" content="text/javascript">
</head><body>
<iframe id="a" src="b.html"></iframe>
<script src="c.js"></script>
</body></html>
[b.html]
<body><p id="p">hoge</p></body>
[c.js]
(function(){
document.getElementById("a").onload = function(){
alert(document.getElementById("a").contentWindow.document);
alert(document.getElementById("a").contentWindow.document.getElementById("p"));
alert(document.getElementById("a").contentWindow.document.getElementById("p").innerHTML);
};
})();
[結果]
Firefox:[object HTMLDocument]→[object HTMLParagraphElement]→hoge
IE:[object]→null
GoogleChrome:undefined
と表示されました。
IEでiframe内の要素の内容を取るにはどうすれば良いのでしょうか?
また、GoogleChromeでiframeのdocumentを取得するにはどうすれば良いのでしょうか?
これらのブラウザ共通でうまくいく書き方はありますか?