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

top.top.location.href='http://xx.com/index.html';

      

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

javascript code http://xx.com/index.html has:

try{
        if(opener) {
            opener.location.href=this.location.href;
            top.close();
        }
    }

      

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

this is a living example

+3


source to share


1 answer


In your code (http://xx.com/index.html)

try{
    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.

0


source







All Articles