js/jquery获取父窗口元素
取父窗口的元素方法:$(selector, window.parent.document);那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document);类似的,取其它窗口的方法大同小异$(selector, window.top.document);$(selector, window.opener.document);$(selec
·
1.取 父窗口 的元素方法:
$(selector, window.parent.document); // 例子: var topWindow = $(window.parent.document); $('.mainContent iframe', topWindow).attr("name"); // 获取class为 .mainContent 下的iframe中属性名为:name 的值 // 获取父窗口,windos当前的, <iframe>, 属性名为 uploadFrame 的。document 为对象。sb 为方法函数 frm = window.parent.window.frames['uploadFrame']; frmDocument = frm.document; frm.sb(3); //sb 是uploadFrame页面里的一个函数
做WEB前端开发的过程中,经常会有这样的需求,用户点击【编辑】按钮,弹出一个对话框,在里边修改相应的值,然后把修改后的值显示在原页面,最后点击保存。用window.parent.document.getElementById().setAttribute("value","")可以很好的解决这个问题。
$("#parent", window.parent.document).val($val);//jQuery写法给父页面传值
2.那么你取 父窗口的父窗口 的元素就可以用:
$(selector, window.parent.parent.document);
3.那么你取 最顶级 的父窗口的元素就可以用:
$(selector, window.top.document); // 获取第一个 <iframe> 元素 (索引为 0) 的 $(selector, window.top.frames[0].document);
4.那么你取 open打开新窗口 的元素就可以用:
$(selector, window.opener.document);
5.获取导航到当前网页的超链接所在网页的URL:
如果要显示某一个网站的超链接跳转到你的网站你可以如下:
var refurl=document.referrer; if(refurl.indexOf("wowgame")>-1){ alert("你的来源网址为:【"+document.referrer+"】目前本站与该站已终止合作。"); location.replace(refurl); }
6. js操作窗口解说:
- frame框架里的页面要改其他同框架下的页面或父框架的页面就用parent
window.opener引用的是window.open打开的页面的父页面。
window.frames对象可以引用iframe里的页面,也可以引用frameset里的页面.- self和window代表本窗口,parent代表父框架,而top代表最顶层框架,如果页面不含框架,则这几个对象相同,如果只含有一层框架,则parent等于top,另外,self和window可以省略
取父窗口的元素方法:$(selector, window.parent.document);
那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document);
类似的,取其它窗口的方法大同小异
$(selector, window.top.document);
$(selector, window.opener.document);
$(selector, window.top.frames[0].document);
更多推荐
已为社区贡献4条内容
所有评论(0)