0

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");
        }   
1
  • by the way "windows" tag has different meaning, I have removed it from this question. Commented Dec 8, 2010 at 9:08

4 Answers 4

3

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';
Sign up to request clarification or add additional context in comments.

Comments

0

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".

Comments

0

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()">

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.