【JavaScript】同じURL内の別のhtmlの要素を変更する
iframeの中にhtmlを読み込ませて表示が完了した後に親のiframeのスタイルを変更したいときに使用
iframeで読み込み終わった後、背景ののiframeの背景色を消したかった。
main.html
<iframe id="test" src="xx.html" height=300 width=300>
xx.html
<script language="javascript" type="text/javascript" src="prototype.js"></script> <script> function init(){ window.parent.$('test').style.backgroundColor = 'transparent'; } </script> <body id="indexMap" onLoad="init();">
xx.htmlが読み込み終わったら実行するbodyの属性のonloadにスクリプトを組み込む
window.parentで同じURL内の別のhtmlの要素を参照できるのでiframeのDOMを拾い背景を変更
*抜粋して書いてるのでしっかり動かないかも…