open new window then redirect.php has ...">

Javascript main window main window

main.php has

<a href="redirect.php" target="_blank">open new window</a>


then redirect.php has'';


When I click on the link to open a new window, redirect.php openin in a new window and redirects to . The problem is here: on this page, the javascript code forces to close this new window and redirect the main window to .

javascript code has:

        if(opener) {


How do I prevent a child window from closing the home page?

this is a living example


source to share

1 answer

In your code (

    if(opener) {
        opener.location.href=this.location.href; // Line-1
        top.close(); // Line-2


1. Line-1 redirects the opener (parent / main window) without closing it, the open property returns a link to the window that opens the window, so if you remove Line-1 it will no longer be redirected.

2. Line-2 closes the current one (the child window shown at the top ), so if you delete this line, it will no longer be closed.

Just remove the whole try block, your problem will be solved and I am confused why you didn't delete these lines yourself, because you knew that these codes were responsible for the problem described in your question.



All Articles