框架(frame)的src属性是只读的,按照正常的思路(document.frames[faramename].src)去修改会提示没有权限,但通过设置document.getElementById[frameid]的src属性或设置弹出窗口的打开目标等方法我们仍可以达到动态修改框架src属性的目的,下面是本次测试代码:
| 程序代码 <iframe name=frame1 id=frame1 src= width=400 height=400></iframe><br /> <input name=btn2 type=button id=btn2 value=按钮一(不行) onclick=document.frames['frame1'].src='http://www.163.com/'; /> <input name=btn3 type=button id=btn3 value=按钮二(不行) onclick=document.frames['frame1'].document.location.href='http://www.sohu.com/'; /> <input name=btn type=button id=btn value=按钮三(可以) onclick=document.getElementById('frame1').src='http://www.hao123.com/'; /> <input name=btn4 type=button id=btn4 value=按钮四(可以) onclick=window.open('http://www.mzwu.com/','frame1'); /> <a href=http://www.CuoXIn.com/ target=frame1>(可以)</a> |