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 ...
随机推荐
- Ruby自学笔记(二)— Ruby的一些基础知识
Ruby安装好之后,我们就可以来实践Ruby语言了. 以下是一些学习到的简单基础知识: 1. 如何执行Ruby文件? 我们编写的Ruby文件是以rb为后缀名的,例如:XXX.rb.当要执行ruby文件 ...
- MVC身份验证及权限管理
MVC自带的ActionFilter 在Asp.Net WebForm的中要做到身份认证微软为我们提供了三种方式,其中最常用的就是我们的Form认证,需要配置相应的信息.例如下面的配置信息: < ...
- VLAN间通信----实验
方法1.增加物理线路 需求:PC0连接SW的F0/1,PC1连接SW的F0/2; SW创建VLAN10,VLAN20; PC0划到VLAN10; PC1划到VLAN20; 现要求借用路 ...
- QVariant(相当于是Java里面的Object,起到一个数据类型“擦除”的作用,可以使用Q_DECLARE_METATYPE进行注册)
=QVariant= [%这个类型相当于是Java里面的Object,它把绝大多数Qt提供的数据类型都封装起来,起到一个数据类型“擦除”的作用.比如我们的 table单元格可以是string,也可以是 ...
- bzoj3339 bzoj3585
两题本质是一样,只不过3585要离散化这种不修改,不强制的问题,显然先考虑离线算法这道题的思路和bzoj1878非常像考虑到如果只是求每个前缀的mex,我们是很容易扫一遍就得出来的我们设为这个位置的m ...
- BZOJ 1072 [SCOI2007]排列perm
1072: [SCOI2007]排列perm Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1268 Solved: 782[Submit][Sta ...
- 搜索(DLX): POJ 3074 3076 Sudoku
POJ 3074 : Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller ...
- oracle 表查询(2)
使用逻辑操作符号 问题:查询工资高于500 或者是岗位为MANAGER 的雇员,同时还要满足他们的姓名首字母为大写的J? or job = 'MANAGER') and ename LIKE 'J%' ...
- N-Queens II——Leetcode
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- WEB性能测试:你应该带上VisualStudio2010
原文地址:http://www.16aspx.com/Article/62 在Web性能测试方面,增加了循环(Loops)和条件(Conditions),让开发人员可以为他们的应用程序写出更复杂,更智 ...