JavaScript—window对象使用
window 对象是 JavaScript 浏览器对象模型中的顶层对象,包含多个常用方法和属性:
1、 打开新窗口
window.open(pageURL,name,parameters)
其中:pageURL 为子窗口路径、name 为子窗口句柄、parameters 为窗口参数(各参数用逗号分隔)
window.open("http://www.cnblogs.com/zhouhb/","open",'height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no');
2 、打开模式窗口
window.showModalDialog("http://www.cnblogs.com/zhouhb/","open","toolbars=0;width=200;height=200");
3 、关闭窗口(兼容IE)
如果网页不是通过脚本程序打开的(window.open();),调用 window.close(); 脚本关闭窗口前,必须先将 window.opener 对象置为null,否则浏览器 (IE7、IE8) 会弹出一个确定关闭的对话框。

老式:
<input type='button' value='关闭窗口' onClick="closeWindow()">
<script language="javaScript">
function closeWindow() {
window.opener = null;
window.open('', '_self', '');
window.close();
}
</script>
或
open(location, '_self').close();
4、 location对象使用
window.location.reload();//刷新当前页
window.location.href="http://www.cnblogs.com/zhouhb/"; //载入其他页面
5 、history对象使用
window.history.go(1); //前进
window.history.go(-1); //后退上一页
6、 子窗体向父窗体传值(17年4月18日,发现代码不好使了。)

父窗口代码:
<!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 type="text/javascript">
var child; //通过判断子窗体的引用是否为空,可以控制它只能打开一个子窗体
function opendialog() {
//例一 这里用window对象作为参数传递(对应子窗口例一)
//window.showModalDialog("child.html", window, "win", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=300,height=80");
//例二(对应子窗口例二)
//window.open("child.html", "Popup", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0,width=300,height=80");
//例三 打开子窗体的同时,对子窗体的元素进行赋值,因为window.open函数同样会返回一个子窗体的引用(对应子窗口例三,此例子不好使)
if (!child) {
child = window.open('child.html');
//需要等待子窗口加载完成,赋值才能成功
child.onload = function() {
child.document.getElementById('name').value = document.getElementById('name').value;
}
}
//例四(对应子窗口例四)
//var resultStr = showModalDialog("child.html", this, "dialogWidth:1000px;dialogHeight:800px");
//document.getElementById('name').value = resultStr;
}
</script>
</head>
<body>
<form>
<input type="text" id="name" value="123" />
<input type="button" id="open" value="open" onclick="opendialog()" />
</form>
</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 type="text/javascript">
function updateParent() {
//例一(对应父窗口例一)
//var pathelem = window.dialogArguments; //子窗口获取传递的参数
//if (pathelem != undefined) {
// pathelem.document.getElementById("name").value = document.getElementById("name").value;
//}
//例二(对应父窗口例一和例二)
//var pathelem = this.opener.document.getElementById('name');
//pathelem.value = document.getElementById('name').value;
//例三(对应父窗口例三,此例子不好使)
window.opener.document.getElementById('name').value = document.getElementById('name').value;
window.opener.child = null;
//例四(对应父窗口例四)
//window.parent.returnValue = document.getElementById('name').value;
this.close();
}
</script>
</head>
<body>
<form>
<input type="text" id="name" />
<input type="button" id="update" value="更新父窗口" onclick="updateParent()" />
</form>
</body>
</html>
JavaScript—window对象使用的更多相关文章
- JavaScript Window 对象
< JavaScript Window Object > && < IE check > JavaScript Window Object Window.loa ...
- javascript Window对象 第16节
<html> <head> <title>浏览器对象</title> <script type="text/javascript&quo ...
- javascript window对象属性和方法
window对象 window对象表示一个浏览器窗口或一个框架.在客户端JavaScript中,window对象是全局对象,所有的表达式 都在当前的环境中计算.也就是说,要引用当前窗口根本不需要特殊的 ...
- 深入理解Javascript window对象
首先看我们的源代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- JavaScript - window对象相关
1 . window对象常用方法 : 写法 : window.方法() 注意 : window可以省略不写 alert(), confirm(), prompt()是JavaScript提供和用户交互 ...
- 14 JavaScript Window对象
Window对象表示一个浏览器窗口或者一个框架. 在客户端JavaScript中,window对象是全局对象,所有的表达式都在当前的环境中计算. Window对象的子对象: JavaScript do ...
- JavaScript——Window对象
1.serTimeout()和setinterval()可用于注册在指定的时间之后单词或者重复调用的函数. 2.window对象的location属性引用的是Location对象,表示该窗口当前显示的 ...
- JavaScript Window对象
1.Window对象的location属性引用的是Location对象,它表示该窗口中当前显示的文档的URL,并定义了方法来使窗口载入新的文档.Location对象的href属性是一个字符串,后者包含 ...
- JavaScript Window对象属性
window 代表浏览器中一个打开的窗口. Window的属性 属性 描述 closed 获取引用窗口是否已关闭. defaultStatus 设置或获取要在窗口底部的状态栏上显示的缺省信息. dia ...
随机推荐
- 计算广义积分$$\int_0^{+\infty}\cos x^p {\rm d}x,\int_0^{+\infty}\sin x^p {\rm d}x, p>1$$
${\bf 解:}$ 在角状域$G=\{z\in\mathbb{C}|0<{\rm Arg}z<\frac{\pi}{2p}\}$上引入辅助函数$e^{iz^p}$, 其中$z^p=|z| ...
- 应用Oracle(用户创建和授权)
使用oracle命令创建用户,并授权. 系统管理员身份登录 cmd中, sqlplus / as sysdba 若登录失败,则 sqlplus system/[数据库创建时指定密码] as sysdb ...
- SequoiaDB 架构指南
1 简介 SequoiaDB(巨杉数据库)是一款分布式非关系型文档数据库,可以被用来存取海量非关系型的数据,其底层主要基于分布式,高可用,高性能与动态数据类型设计,与当前主流分布式计算框架 Hadoo ...
- codeforces C. k-Tree
思路:dp[i][j]表示和为i,最大值为j的方案数. #include <cstdio> #include <cstring> #include <algorithm& ...
- 工程师必知ZigBee技术问答精华汇总
本文是关于ZigBee技术的一些基础知识.行业应用方面的精华汇总.希望通过本文的分析,能让大家对ZigBee技术的起源.发展.特点.前景及其在通信网络中的相关应用有全面直观的了解. 1.基础知识篇 Q ...
- 想做Android Wear开发?你得先搞明白这四件事
手环和手表的腕上穿戴之争,随着Apple Watch发布和Android Wear不断完善而告一段落.尽管续航上略有缺陷,但手表以其类似手机可扩展的生态环境赢得了众多巨头的支持. Google曾透露, ...
- oracle中的exists 和not exists 用法详解(转)
有两个简单例子,以说明 “exists”和“in”的效率问题 1) select * from T1 where exists(select 1 from T2 where T1.a=T2.a) ; ...
- 一段JAVA签名算法的PHP改写
源代码是这样的: public class AuthorizationSignature { public static String createSignature(String verb, Str ...
- windows7+iis7+php的配置
最近在找工作,人被逼了,所以没事就学习php了.以下是开发环境的搭建: 环境搭建 然后就是解析php脚本的两种配置方法: fastCgiModule与ISAPI方式 两种配置方法 本文为转载...
- java学习之变量
看完了常量,那我们来看下变量. 变量顾名思义,也就是能变化的量,也就是说已经定义之后它的值仍然是可以变的,不像常量一经定义便不能够改变了.比如说现在我们需要一个数,需要用户输入之后才能,确定这个数是几 ...