有3个页面,A通过IFRAME指向B,B通过重定向指向C,请问怎么能在A中访问到C中的button?
page A :
<IFRAME name="frameA" id="frameA" src="pageB.html?pageC.html" width="100%" height="100%">
</iframe>page B:
<script>
//newdoc取出?后面的参数
var newdoc = document.location.search.substring(1);
window.location.href=newdoc;
</script>page C:
<button id="buttonC">click me</button>

解决方案 »

  1.   

    document.getElementById("frameA").document.getElementBy("buttonC");但是,需要确保在page c load之后再执行这段代码。
      

  2.   

    回一楼,用这种写发试验了一下,不行。
    如果没有重定向,直接从iframe中获取子页面的话,可以这样写:var tset = window.document.getElementById("frameA").contentWindow.document.getElementById("buttonC");但有了重向转到其他页面,window.location.href=XXXX,就无法继续向下访问了。
    主要是这个无法解决。
      

  3.   

    感谢1楼,后来证明是可以直接访问的,关键是要等重定向之后,一开始代码放在<body onload="">
    里面所以是不行的。
    上面的写法我试验不成功,我的写法是:
    window.document.getElementById("frameA").contentWindow.document.getElementById("buttonC");