window.parent与window.openner 之前的总结
今天总结一下js中几个对象的区别和用法:
1.首先来说说 parent.window与top.window的用法
"window.location.href","location.href" 是本页面跳转
"parent.location.href" 是上一层页面跳转
"top.location.href" 是最外层的页面跳转
举例说明:
如果A,B,C,D都是窗口,D是C的iframe,C是B的iframe,B是A的iframe,
D -> C -> B-> A 框架顺序 A是最外层的框架
如果D中js这样写
"window.location.href"、"location.href": D页面跳转
"parent.location.href": C页面跳转
"top.location.href": A页面跳转 现在终于明白了连接的时候target的用法了:
_blank: 重新打开一个窗口
_parent:父窗口执行重定向
_self: 自身页面重定向
_top: 第一个父窗口重定向
综上所述可知:parent.window:父窗口对象 top.window:第一个父窗口的对象
window.parent 是iframe页面调用父页面对象,当我们想从iframe内嵌的页面中访问外层页面是可以直接利用window.parent获取;
例子如下:
A.html
<html>
<head>
<title>父页面</title>
</head>
<body>
<form id="form1" action="">
<div>
输入值:
<input type="text" name="username" id="username" /><br />
<iframe src="b.html" width="400px" height="300px"></iframe>
</div>
</form>
</body>
</html>
B.html
<html>
<head>
<script type="text/javascript">
function getpValue()
{
document.getElementByIdx_x_x_x("span1").innerText=window.parent.document.getElementByIdx_x_x_x("username").value;
}
</script>
</head>
<body>
<span>文本框值为:</span><span id="span1"></span><br />
<input type="button" value="获取父窗口内的文本框值" onclick="getpValue();">
</body>
</html>
document.frames对象可以引用iframe里的页面,也可以引用frameset里的页面.
可以这样
document.frames[0].document.getElementById('xx');
可以这样
document.frames[0].document.body.innerHTML;
window.opener 是window.open或超链接<a> 打开的子页面调用父页面对象
例子如下
a.html
<html>
<head>
<title>父页面</title>
<script type="text/javascript">
function openB()
{
window.open('b.html','b','width=400,height=200,status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=200,top=100');
}
</script>
</head>
<body>
<form id="form1" action="">
<div>
输入值:
<input type="text" name="username" id="username" /><br />
<input type="button" value="打开窗口B" onclick="openB();" /><br />
<a href="b.html" target="_blank">超链接打开B页面</a>
</div>
</form>
</body>
</html>
b.html
<html>
<head>
<script type="text/javascript">
function getpValue()
{
document.getElementByIdx_x_x_x("span1").innerText=window.opener.document.getElementByIdx_x_x_x("username").value;
}
</script>
</head>
<body>
<span>文本框值为:</span><span id="span1"></span><br />
<input type="button" value="获取父窗口内的文本框值" onclick="getpValue();">
</body>
</html>
window.parent与window.openner 之前的总结的更多相关文章
- window.parent与window.openner区别介绍
今天总结一下js中几个对象的区别和用法: 首先来说说 parent.window与top.window的用法 "window.location.href"."locati ...
- window.parent与window.openner
window.parent与window.openner区别介绍 作者: 字体:[增加 减小] 类型:转载 今天总结一下js中几个对象的区别和用法,对这几个概念混淆的朋友可以看看 今天总结一下js中几 ...
- JavaScript中,window.opener是什么?window.parent和window.opener有啥区别?
来自CSDN的问答: window.opener是什么啊? ++++++++++++++++++++++++++++++++++++++++++++++++++ 弹出本窗体的句柄 比如你想点一个按钮直 ...
- window.parent与window.opener的区别
有这样一个需求,弹出一个新窗口 并从该新页面的select选择框中选择需要的类别,再返回到之前的父窗口页面的某个文本框中.这里就要用到window.parent和window.opener 如题两种方 ...
- (转)window.parent和window.opener区别
下面一段代码是关于window.parent和window.opener区别 来讲的,我们如果要用到iframe的值传到另一框架就要用到window.opener.document.getElemen ...
- window.parent 与 window.opener
window.parent针对iframe,window.opener针对window.open 父页面parent.jsp: <%@ page language="java" ...
- window.parent与window.opener的区别与使用
window.parent 是iframe页面调用父页面对象 举例: a.html 如果我们需要在b.html中要对a.html中的username文本框赋值(就如很多上传功能,上传功能页在ifrma ...
- window.parent 与 Window.top
window.parent 返回当前窗口的父窗口对象. 如果一个窗口没有父窗口,则它的 parent 属性为自身的引用. 如果当前窗口是一个 <iframe>, <object> ...
- window.parent 、window.top及window.self 详解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口. 1. window.self ...
随机推荐
- “耐撕”团队2016.04.12站立会议
1.时间 : 19:15--19:30 共计15分钟. 2.成员 : Z 郑蕊 * 组长 (博客:http://www.cnblogs.com/zhengrui0452/), P 濮成林(博客:ht ...
- 使用PowerDesigner创建表并导入到数据库
使用PowerDesigner创建表并导入到数据库 刚刚学习使用PowerDesigner进行数据库的创建,下面我就分享一下如何创建表并导入到数据库. 1.首先到网上下载一下PowerDesigner ...
- 另一套Oracle SQL练习题,更新参考答案
题干: create table student( sno ) primary key, sname ), sage ), ssex ) ); create table teacher( tno ) ...
- c#创建ISS站点
private void CreateWebSite() { try { string installPath = "C:\\Program Files\\MyWeb"; stri ...
- str内部方法
代码 #str内部功能 name=' aK am\til.L iu' age=18 num=-11 ab='#' ac=('1','2','3','4','5','6','7') print(dir( ...
- jeecms内容显示条数
1.按照1.2.3.4.5顺序显示 <div class="index-news"> [@cms_channel id='1'] <h2><span& ...
- ubuntu设置屏幕亮度
楼主的本本是acer4750g ,系统是ubuntu kylin 14.04 原 笔记本ubuntu14.04无法调节屏幕亮度 http://my.oschina.net/lhplj/blog/397 ...
- float,double,decimal使用讨论
注意:有效位:小数点前后的全部数字,不包括小数点在内 float:浮点型,含字节数为4,32bit,数值范围为-3.4E38~3.4E38(7个有效位) double:双精度实型,含字节数为8,64b ...
- C#获取本机的MAC地址
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.M ...
- FireFox & Chrome 使用技巧
一 FireFox 1 安装调试工具 Firebug , HttpRequester 2 打开响应式布局 打开菜单 -> 开发者 -> 响应式设计视图 二 Chrome 1 修改Chrom ...