window.opener problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rexdreamer
    New Member
    • Aug 2009
    • 3

    window.opener problem

    Gotta problem. I have a page that onload a popup window comesup, within that popup window there is a link to another .htm page. I need that link to display the .htm file in the main browser window.(use the opener keyword to reference the main browser window, and the location.href property to specify the document to be displayed(form. htm)in that window., and slo close the current window.
    Below is what i have right now, it loads the popup window(subscrip tions)correctly , when i press the link in the popup window it opens the form.htm in the popup window instead of the main browser window.
    Code:
    <title>Subscription</title>
    <link href="cover.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    function showForm(URL){    
          window.opener.location.href="form.htm";
          window.close();
    }            		
    	
    </script>
    </head>
     
    <body>
     
    <div id="main">
    <p><a href="form.htm">
       <b>Order 12 issues <br />for: $9.95*</b>
       </a>
    </p>
    <p><img src="cover.jpg" alt="The Civil War Journal" /><br />
       *25% off the <br />newsstand price!</p>
    </div>
     
    </body>
    </html>
    The form.htm still opens in the popup window instead of the main browser window
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by rexdreamer
    The form.htm still opens in the popup window instead of the main browser window
    why should it open in the main window? although you made a JS function, it is called nowhere, leaving the link as it is (i.e. normal behaviour).

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I think you need to use a closure, and its always a good idea to check if the parent window is open before referring to it.
      Code:
      if(window.opener && !window.opener.closed){
        var winOpener = window.opener;
        winOpener.location.href="form.htm";
        window.close();
      }

      Comment

      Working...