开发者

open new windows in javascript

开发者 https://www.devze.com 2023-01-30 00:38 出处:网络
hi how to use 开发者_开发技巧javascriptscript to open a new window and then closing the current window..

hi how to use 开发者_开发技巧javascriptscript to open a new window and then closing the current window..

currently, i can only open a new window, however my current window is still left open.

Code:

function newfunction()
        {
            window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
        }   


Opening a new window and closing the old one sounds very much like changing the current page to me. Use location.href = 'newurl'.

And if you want to change its size and so on, that can also be done.

window.innerWidth = 300;
window.innerHeight = 300;
location.href = 'newurl';


use like you said window.open and then in the main window window.close(). But if you use like this, the browser will ask you "This website wants to close this window blabla".


add window.opener.close();

 function newfunction()
            {
                window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0"); 
                window.opener.close();

            }   

or add this on the index.html file whenever a new window open it will close the parent window

<body onload="window.opener.close()">


Here is the code you need:

function newfunction()
{
   window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
   window.close();
}

This will work only if the current window was opened via script as well, otherwise IE show warning dialog and other browsers might simply ignore it.

0

精彩评论

暂无评论...
验证码 换一张
取 消