質問者 ひな
投稿日 2004/4/5(月) 01:59:30
こんにちは。 動的に生成したインラインフレームのページを変更できません。 以下にサンプルソースを掲載しますのでよろしくお願いいたします。 環境は以下の通りです。 winXp pro IE ver 6.0 <html> <head> <title>index</title> <meta http-equiv="content-type" content="text/html; charset=shift_jis"> <script language="javascript"> // iframe id カウント var iFrameCount = 0 function addIFrame(left, top, width, height) { var html = "<table border=\"0\">" +"<tr>" +"<td>" +"<iframe id=\"iFrame_"+iFrameCount+"\" src=\"http://www.google.com\" style=\"width:300;height:300;\" frameborder=\"1\"><\/iframe>" +"<\/td>" +"<\/tr>" +"<\/table>" var layoj = document.createElement('div') layoj.setAttribute('id','layerDiv') layoj.innerHTML = html layoj.style.position = 'absolute' layoj.style.left = left + 'px' layoj.style.top = top + 'px' layoj.style.width = width + 'px' layoj.style.height = height + 'px' //divをbodyへ追加 document.body.appendChild(layoj) // iframe id カウントを増加 iFrameCount++ } function change(iFrameId) { var iFrame = document.getElementById(iFrameId); // エラーになる iFrame.location.href = "http://yahoo.co.jp" // これならうまくいくのですが...意図した目的とは異なってしまいます iFrame_0.location.href = "http://yahoo.co.jp" } </script> </head> <body onload="addIFrame(50, 50, 100, 100)"> <input type="button" onClick="addIFrame(200, 200, 200, 200)" value="ifremを追加"> <input type="button" onClick="change('iFrame_0')" value="ifrem内のページを変更"> </body> </html>
プロバイダ参照: |
回答者 sim
[削除]
投稿日 2004/4/5(月) 12:26:59
location.hrefを利用するのであれば、IDを指定ではなく、フレーム名を選択するとよろしいかと思います。 parent.フレーム名.location.href('URL') 逆にdocument.getElementById('ID').src=URL; でも出来そうな気がしますが。 |
質問者 ひな
[削除]
投稿日 2004/4/5(月) 13:27:20
simさん、有難うございます。 >逆にdocument.getElementById('ID').src=URL; これで対応できました。 またなにかありましたらよろしくお願いいたします。 |
このページは終了したので返信(回答)は書きこめません
Web裏技 |