喜如何使用javascriptscript打开一个新的窗口,然后关闭当前窗口..打开新窗口的JavaScript
目前,我只能打开一个新的窗口,但我的当前窗口依然敞开。
代码:
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
}
喜如何使用javascriptscript打开一个新的窗口,然后关闭当前窗口..打开新窗口的JavaScript
目前,我只能打开一个新的窗口,但我的当前窗口依然敞开。
代码:
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
}
打开一个新的窗口和关闭旧听起来很像改变当前页面给我。使用location.href = 'newurl'
。
如果你想改变它的大小等,也可以这样做。
window.innerWidth = 300;
window.innerHeight = 300;
location.href = 'newurl';
使用像你说的window.open,然后在主窗口window.close()。但是,如果你这样使用,浏览器会问你:“这个网站想关闭这个窗口blabla”。
添加window.opener.close();
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
window.opener.close();
}
或添加本就index.html
文件,只要打开一个新窗口将关闭父窗口
<body onload="window.opener.close()">
以下是你需要的代码:
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
window.close();
}
只有在当前窗口通过sc打开时才能使用ript,否则IE显示警告对话框和其他浏览器可能会简单地忽略它。
顺便说一句,“windows”标记有不同的含义,我已经从这个问题中删除了它。 – 2010-12-08 09:08:10