Search code examples
javascripttargetwindow.open

javascript: Open an URL from an window.open page back in the original page


I'm opening a smaller web browser window from the "main" web page. The "child" window contains links like the following...

<a onclick="javascript:window.open('http://someplace.com/','_blank');">Someplace</a>

But instead of using target "_blank" I would like to use the name of the original, "main" web page window and open the links back in that window. Any suggestions how to do that?


Solution

  • follow this example to help you solve your problem:

    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function openWin()
    {
    myWindow=window.open('','','width=200,height=100');
    myWindow.document.write("<p>This is 'myWindow'</p>");
    myWindow.focus();
    myWindow.opener.document.write("<p>This is the source window!</p>");
    }
    </script>
    </head>
    <body>
    
    <input type="button" value="Open 'myWindow'" onclick="openWin()" />
    
    </body>
    </html>