window.open打开子窗口后关闭父窗口实现
2018-02-08 12:23
435 查看
<script type="text/javascript"> newWindow=window.open ('http://www.baidu.com', "name", "") ; window.opener=null; window.open("","_self"); window.close(); </script> 在ff中父窗口不能关闭。在地址栏里输入about:confit找到dom.allow_scripts_to_close_windows这一项,并把这项改为true就可能了 说明:Window对象的opener属性与打开这个窗口的父窗口相联系,当访问子窗口中的opener属性时,返回的是父窗口。通过这个属性,可以使用父窗口对象中的方法和属性。 解决思路:把父窗口的父窗口声明为null(window.opener=null),在让父窗口自己把自己声明为子窗口 (window.open("","_self")),这样父窗口自己也变成“子窗口”了,当用window.close()关闭时,就不会出现提示框 了。 window.open()函数说明: 函数原型:window.open(URL,name,param) URL:要弹出的新的网页 name:弹出新网页的名字(不是文件名),可为空。 param: height:窗口的像素高度。为与先前版本相兼容,这个参数仍然存在。但在JavaScript1.2中被innerHeight取代。 width:窗口的像素宽度。为与先前版本相兼容,这个参数仍然存在。但在JavaScript1.2中被innerWidth取代。 location: 是否显示地址栏 menubar:是否显示菜单栏 titlebar: 是否显示标题栏 toolbar: 是否显示工具栏 resizable:指明窗口大小是否可以调整 top=0 窗口距离屏幕上方的象素值 left=0 窗口距离屏幕左侧的象素值 status: 是否显示状态栏
完整示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body onload="openwin('http://www.baidu.com')">top
<script>
function openwin(url) {
//alert(screen.width+"*"+screen.height) ;
//openwin('left.html')
var w = screen.width -10;
var h = screen.height -85;
window.open (url, '全屏窗口测试', 'height='+ h + ', width=' + w + ', top=0,left=0 , toolbar =no, menubar=no, scrollbars=no, resizeable=no, location=no, status=yes')
window.opener=null;
window.open("","_self");
window.close();
}
</script>
</body>
</noframes></html>
完整示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body onload="openwin('http://www.baidu.com')">top
<script>
function openwin(url) {
//alert(screen.width+"*"+screen.height) ;
//openwin('left.html')
var w = screen.width -10;
var h = screen.height -85;
window.open (url, '全屏窗口测试', 'height='+ h + ', width=' + w + ', top=0,left=0 , toolbar =no, menubar=no, scrollbars=no, resizeable=no, location=no, status=yes')
window.opener=null;
window.open("","_self");
window.close();
}
</script>
</body>
</noframes></html>
相关文章推荐
- window.open打开子窗口后关闭父窗口实现
- js关闭当前窗口,window.close()方法只能是window.open打开的才能执行关闭
- 用javascript实现始终保持打开同一个子窗口以及关闭父窗口同时自动关闭所有子窗口
- 由window.open打开的窗口如何通知父窗口自己已经关闭
- 如何用window.showModalDialog打开弹出子窗口,并在子窗口关闭时刷新父窗口
- window.open()实现打开窗口
- window.open 打开子窗口,关闭所有的子窗口
- 函数window.open实现关闭所有的子窗口
- window.open 打开的子窗口 闪一下即自动关闭问题
- window.open()理解以及如何用window.open()实现窗口关闭
- window.open 打开子窗口,关闭所有的子窗口
- window.open()方法打开的子窗口怎样调用父窗口的方法呢?
- window.open,自动打开新窗口并且自动关闭新窗口,可以作为增加点击率使用
- window.open打开的窗口关闭后刷新父页面的子页面
- Window.open 实现导航与打开窗口,导航到一个特定链接地址,也可以打开一个新的浏览器窗体
- window.open 打开的窗口关闭后
- 用javascript实现始终保持打开同一个子窗口以及关闭父窗口同时自动关闭所有子窗口
- js -- 打开新窗口(window.open)、关闭窗口(window.close)
- 在父窗口中得知 window.open()出的子窗口关闭事件的方法(定时器实现)
- js window.open()实现打印,如何在关闭打印窗口时刷新父窗口