关于iframe你不知道的那些事
假设a.html包含了一个iframe,
iframe的id和name是:myIframe,链接到b.html
在a.html 有两个javascript语句:
alert(window.myIframe);
alert(docuemnt.getElementById('myIframe'));
你会发现第一句得到的是 [object window]
而第二句话得到的是:[object HTMLIFrameElement]
所以:window.myIframe.location.href = 'xxxx.html'是可以的
而:docuemnt.getElementById('myIframe').location.href = 'xxxx.html'无法运行。
因为:window对象才具有location属性
同样:window.myIframe.width = 100px 无法运行
而:docuemnt.getElementById('myIframe').width = 100px 可以运行。
因为:window对象不具备width属性,而htmlElement对象才具备。