框架(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> |