0

I have a scenario like this.

Window 1->opens->modal popup->opens-> window 2.

Modal popup is launched using showmodaldialog method from window 1. From the modal popup a normal window (window 2) is launched using "window.open" method. On launching the window 2, the modal popup is closed using self.close() in the popup window's javascript.

Now the windows open are window 1 & window 2. I want to transfer the focus of the window 1 from window 2. is there anyway this can be done?

I have removed other programming code due to security restrictions at the workplace. However, given below is the gist of the code for the scenario I have explained above. Please let me know if there is anything that can be done to solve this problem?

Following is my code:

  • Parent Window (window 1):

    <html>
     <head><title> Parent Window <title>
      <script> 
          function show_popup(){ 
          base_win=window; 
          var win1=window.showModalDialog("Child_Window 1.html",base_win,"dialogHeight:500px;dialogWidth:500px;dialogLeft:300");
           } 
       </script> 
      </head>
      <body> 
          This is the parent Window 
          <input type="button" id="button1" value="click this" onclick="javascript:show_popup();">
      </body> 
    </html>
    
  • Modal Popup Window:

    <html>
     <head>
       <title>Child Window 1</title>
       <script> 
             function show_window(){ 
             var win1=window.open("Child_Window 2.html","");
             self.close();
              }
       </script>
      </head>
      <body> 
          This is the Child Window 1 
           <br>
           <br>
           <input type="button" id="but1" value="click this" onclick="javascript:show_window();">
       </body>
     </html>
    
  • Child Window (window 2):

    <html>
      <head>
         <title>Child Window 2</title>
          <script> 
              function goto_parent(){
               var w = window.opener; 
               window.opener = self; 
               w.focus(); 
               } 
           </script> 
         </head> 
         <body> 
             This is the child Window 
              <input type="button" id="but1" value="parent window" onclick="javascript:goto_parent();">
         </body>
     </html>
    
4

1 回答 1

0

在 ModalDialog 未关闭之前,窗口 1 将无法运行。因此,在基本窗口中的以下代码之后立即调用第三个窗口的实例 -

 var win1=window.showModalDialog("Child_Window 1.html",base_win,"dialogHeight:500px;dialogWidth:500px;dialogLeft:300");

关闭 ModalDialog 后,基本窗口将调用所需窗口的焦点。

于 2013-08-12T07:02:25.000 回答