如何用JS打开新窗口,并关闭原来窗口

如题所述

做一个触摸屏查询系统,要打开新页面后关闭父界面 百度之functionopenNewWindow() { window.open("Index.aspx","","left=30,top=30,toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no,location=no,directories=no,copyhistory=no,height=620,width=820"); window.opener=null; window.open("","_self"); window.close(); }
这样写的话,由于窗口拦截的原因,会使新窗口打不开,而且原来的窗口也被关闭了
于是再查询找到解决去方法在新页面中onload="window.opener。opener=null; window.opener.close();"
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-03-09
我来把格式怎规范点:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function openNewWindow() {
window.open("forwardnewpage.jsp","","left=30,top=30,height=620,width=820,toolbar=no,menubar=no,scrollbars=no,resizable=no,status=no,location=no,directories=no,copyhistory=no");
window.opener=null;
window.open("","_self");
window.close();
}
</script>
</head>
<body>
<input type="button" value="打开新窗口关闭旧的" onclick="openNewWindow()">
</body>

</html>
新窗口页面代码(如果浏览器允许弹窗可以不要onload这段代码):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>new page</title>
</head>
<body onload="window.opener.opener=null; window.opener.close();">
<table border="1" cellpadding="1" cellspacing="0" align="center" style="text-align: center;">
<caption>表格标题</caption>
<tr>
<th>标题1</th>
<th>标题2</th>
<th>标题3</th>
</tr>
<tr>
<td>测试</td>
<td>测试</td>
<td>测试</td>
</tr>
<tr>
<td>测试</td>
<td>测试</td>
<td>测试</td>
</tr>
</table>
<br>
</body>
</html>