javascript基础-窗口对象(window)
2016-05-07 22:28
627 查看
1.top
该变更永远指分割窗口最高层次的浏览器窗口。如果计划从分割窗口的最高层次开始执行命令,就可以用top变量。
2.opener
opener用于在window.open的页面引用执行该window.open方法的的页面的对象。例如:A页面通过window.open()方法弹出了B页面,在B页面中就可以通过opener来引用A页面,这样就可以通过这个对象来对A页面进行操作。
3.parent
parent用于在iframe,frame中生成的子页面中访问父页面的对象。例如:A页面中有一个iframe或frame,那么iframe或frame中的页面就可以通过parent对象来引用A页面中的对象,这样就可以获取或返回值到A页面中。
4.另外self 指的是当前窗口
(1)window.top
(2)window.opener
(3)window.parent
(4)self
利用<frameset>、<frame>给主页面划分窗口top、left、right,将主页面划分成三个页面窗口
(5)parent与opener的区别 parent指父窗口,在frameset中frame的parent就是frameset窗口; opener指用window.open等方式创建的新窗口对应的原窗口; parent是相对于框架来说父窗口对象; opener是针对于用window.open打开的窗口来说的父窗口,前提是window.open打开的才有document.parentWindow.menthod()調用父頁面的方法
该变更永远指分割窗口最高层次的浏览器窗口。如果计划从分割窗口的最高层次开始执行命令,就可以用top变量。
2.opener
opener用于在window.open的页面引用执行该window.open方法的的页面的对象。例如:A页面通过window.open()方法弹出了B页面,在B页面中就可以通过opener来引用A页面,这样就可以通过这个对象来对A页面进行操作。
3.parent
parent用于在iframe,frame中生成的子页面中访问父页面的对象。例如:A页面中有一个iframe或frame,那么iframe或frame中的页面就可以通过parent对象来引用A页面中的对象,这样就可以获取或返回值到A页面中。
4.另外self 指的是当前窗口
(1)window.top
(2)window.opener
(3)window.parent
(4)self
利用<frameset>、<frame>给主页面划分窗口top、left、right,将主页面划分成三个页面窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <frameset rows="20%,*"> <frame src="top.html" name="top"/> <frameset cols="30%,*"> <frame src="left.html" name="left"/> <frame src="right.html" name="right"/> </frameset> </frameset><noframes></noframes> </html>top页面窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript"> function demo(){ parent.frames[0].document.bgColor="blue"; alert(parent.frames.length); } </script> </head> <body> <input type="button" value="颜色" onclick="demo()" /> <a href="http://www.google.com" target="right">谷歌</a> </body> </html>left页面窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> function demo(){ parent.frames[0].location.href="http://www.baidu.com"; } </script> </head> <body> <input type="button" value="百度" onclick="demo()" /> </body> </html>right页面窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> function demo(){ parent.frames[1].location.href="http://www.sina.com"; } </script> </head> <body> <a href="javascript:demo()">新浪</a> </body> </html>
(5)parent与opener的区别 parent指父窗口,在frameset中frame的parent就是frameset窗口; opener指用window.open等方式创建的新窗口对应的原窗口; parent是相对于框架来说父窗口对象; opener是针对于用window.open打开的窗口来说的父窗口,前提是window.open打开的才有document.parentWindow.menthod()調用父頁面的方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> function demo(){ window.open("3-4.html"); } </script> </head> <body> <input type="button" value="点击" onclick="demo()" /> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script> document.parentWindow.document.bgColor="red"; </script> </head> <body> </body> </html>附:Window对象、Parent对象、Frame对象、Document对象和Form对象的阶层关系Window对象→Parent对象→Frame对象→Document对象→Form对象,如下: parent.frame1.document.forms[0].elements[0].value;
相关文章推荐
- Linux下XWindow图形界面的基本概念
- Hegemon:使用 Rust 编写的模块化系统监视程序
- mysql 前几条记录语句之(limit)
- top、clientTop、scrollTop、offsetTop
- 快速掌握Node.js之Window下配置NodeJs环境
- 使用 TOP 子句限制UPDATE 语句更新的数据
- asp中 select top 问题!~
- 判断window.onload是否多次使用的方法
- Javascript中封装window.open解决不兼容问题
- jquery自定义插件开发之window的实现过程
- jquery自定义插件――window的实现【示例代码】
- window.returnValue使用方法示例介绍
- javascript类型系统 Window对象学习笔记
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别
- window系统的Rsync同步实战分析第1/2页
- JavaScript中window、doucment、body的解释
- JavaScript的document对象和window对象详解
- window.onload和$(function(){})的区别介绍
- JavaScript中的Window窗口对象
- window.opener用法和用途实例介绍