js操作iframe的一些方法介绍

更新时间:2023-06-20 23:06:12 阅读: 评论:0

js操作iframe的⼀些⽅法介绍
存在跨域访问限制。
chrome:iframeElement. contentWindow
现在完成时的结构
firefox: tWindow
带胜的成语
ie6:tWindow
⽂章Iframes, onload, and document.domain中说“he iframe element object has a property called contentDocument that contains the iframe's document object, so you can u the parentWindow property to retrieve the window object.”意思就是⼀些浏览器可以通过tDocument.parentWindow获得iframe的window对象。但经过测试firefox、chrome的tDocument对象没有parentWindow属性。
(javascript)
复制代码代码如下:
function getIframeWindow(element){
return  tWindow;
//return  tWindow || tDocument.parentWindow;
}
存在跨域访问限制。
chrome:tDocument
firefox:tDocument
ie:tWindow.document
备注:ie没有tDocument属性。
(javascript)
复制代码代码如下:
var getIframeDocument = function(element) {
return  tDocument || tWindow.document;
};
存在跨域访问限制。
⽗页⾯:window.parent
顶层页⾯:p
适⽤于所有浏览器
存在跨域访问限制。
window.frameElement(类型:HTMLElement),适⽤于所有浏览器
⾮ie浏览器都提供了onload事件。例如下⾯代码在ie中是不会有弹出框的。
(javascript)炎热夏天
复制代码代码如下:
var ifr = ateElement('iframe');
ifr.src = 'www.jb51/index.php';
alert('loaded');
鱼骨辫教程一步一步教
};
document.body.appendChild(ifr);
但是ie却⼜似乎提供了onload事件,下⾯两种⽅法都会触发onload盘发图片
特点的近义词
复制代码代码如下:
<iframe  onload="alert('loaded');"  src="www.jb51/index.php"></iframe>
//只有ie才⽀持为createElement传递这样的参数
复制代码代码如下:
党外人士座谈会var ifr = ateElement('<iframe  onload="alert('loaded');" src="www.jb51/index.php"></iframe>');  document.body.appendChild(ifr);
由于iframe元素包含于⽗级页⾯中,因此以上⽅法均不存在跨域问题。
经济运行分析
实际上IE提供了onload事件,但必须使⽤attachEvent进⾏绑定。
复制代码代码如下:
var ifr = ateElement('iframe');
ifr.src = 'b.jb51/b.php';
if (ifr.attachEvent) {
ifr.attachEvent('onload',  function(){ alert('loaded'); });
} el {
}
document.body.appendChild(ifr);
window.frames可以取到页⾯中的帧(iframe、frame等),需要注意的是取到的是window对象,⽽不是HTMLElement。复制代码代码如下:
var ifr1 = ElementById('ifr1');
var ifr1win = window.frames[0];
ifr1win.frameElement === ifr1;  // true
ifr1win === ifr1;    // fal

本文发布于:2023-06-20 23:06:12,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1001682.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对象   代码   没有
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图