Child window target not working.

<html>
     <head>
     <title>This is open pop-up</title>
     <script language="Javascript" >

     var childwin;
     var popupName;
     window.name = "PurchasePage";

     function OnLoadEvent()
     {
          childwin = window.open('',"PurchasePagePopup",'height=400,width=390,status=yes,dependent=no,scrollbars=yes,screenX=500,screenY=250,left=450,top=150');
          childwin.focus();          
          document.downloadForm.submit();
          }

     </script>
     </head>
     <body onload="OnLoadEvent();" >
     <form name="downloadForm" action="acsURL.html" method="POST" target="PurchasePagePopup">
          <input type="hidden" name="PaReq" value="true">
          <input type="hidden" name="TermUrl" value="opodo.jsp">
     </table>
     </form>
</body>
</html>

I am using this code to open a pop and set the parent windows target to a pop-up. Sometimes it opens 3 windows, instead of two.

The 3 windows being, parent window,another child pop window, and third the window coming out of the target. This happens only some time. I dont understand, when I am setting the parent windows target as the child window, why the response is displayed in a new window and not the child pop-up.

Please help me out.

Regards
OM





osinghAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
gator4lifeConnect With a Mentor Commented:
I think the reason you may be having a problem is due to the timing of the scripts you are using.  If the popup window finishes loading before the submit fires, then the target knows where to go, since the new windows name has been set.  If the popup window does not finish loading before the submit fires, then the target does not think the new window is there, and thus creates another window.

Here is what I would do to completely solve this problem.  Create a small file that will temporarily be loaded into the pop-up window when it is first loaded.  This small file will only contain one JavaScript function that will fire when the onload event of the <body> of that file is triggered.  Therefore, the function in the small file will only run when the window has completely loaded, ensuring that the pop-up windows name is set and ready to be targeted.  This function will then refer back to the parent page and submit the form.

Here is what I explained above shown in code:

==========================================================
Parent Page
==========================================================

<html>
     <head>
          <script type="text/javascript">
          <!--
               var oChildWin;

               function OnLoadEvent() {

                    oChildWin = window.open('tempPage.html', 'PurchasePagePopup', 'height=400,width=390,status=yes,dependent=no,scrollbars=yes,screenX=500,screenY=250,left=450,top=150');
               }
          //-->
          </script>
     </head>
     <body onload="OnLoadEvent()">
          <form name="downloadForm" action="acsURL.html" method="post" target="PurchasePagePopup">
               <input type="hidden" name="PaReq" value="true">
               <input type="hidden" name="TermUrl" value="opodo.jsp">
          </form>
     </body>
</html>

==========================================================
tempPage.html
==========================================================

<html>
     <head>
          <script type="text/javascript">
          <!--
               function SubmitParentForm() {
                   
                    window.opener.document.forms('downloadForm').submit();
               }
          //-->
          </script>
     </head>
     <body onload="SubmitParentForm()">
          <br>
     </body>
</html>

==========================================================

Try this out and see if it works.  Let me know if you have any questions.

gator4life
(chomp, chomp)
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: gator4life {http:#8193882}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.