1

I have a JavaScript that opens a new window when a button is clicked. It works fine. But, I want to re-direct the Parent Window (i.e. the current page) once the new window is opened.

Here is my script :

<script type="text/javascript">
function OpenWindow() {
    window.open('/My_Folder/file.php',
                'newwindow',
                config='height=670,width=1400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
}
</script>

And, the button:

<input type="button" value="Submit" onclick="OpenWindow()">

So, in order to be able to re-direct the Parent Window, after the new window has popped up, I added a simple line to my JS function :

<script type="text/javascript">
function OpenWindow() {
    window.open('/My_Folder/new_file.php', 'newwindow', 
                config='height=670,width=1400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no, status=no');
}

setTimeout(1000, '/My_Folder/PHP/file_2.php');
</script>

Meaning, after the new window has popped up, the Parent Window should re-direct in 1 second.

But, for some reason, it's not working.

Online searches have only given me solutions for situations involving the reverse : re-direct the Parent Window after CLOSING the child-window.

I want to re-direct the Parent Window after opening a new (child) window.

UPDATE

So far, I've tried these 3 ways :

   (a)  <script type="text/javascript">
   function OpenWindow()    {
   window.open ('/My_Folder/new_file.php', 'newwindow', 
   config='height=670, width=1400,   
   toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, 
   directories=no, status=no');
   window.top.location.href = '/My_Folder/PHP/file_2.php'
   }
   </script>


 (b)  <script type="text/javascript">
 function OpenWindow() { window.open('/My_Folder/file.php','newwindow',         
 config='height=670,width=1400,toolbar=no,menubar=no,scrollbars=no,
 resizable=no, location=no,directories=no,status=no');
 settimeout( function(){document.location='/My_Folder/PHP/file_2.php'}, 1000    
 );
 }
 </script>


 (c) <script>
     function OpenWindow()    {
    window.open ('/My_Folder/new_file.php', 'newwindow', 'height=670, 
    width=1400, toolbar=no, menubar=no, scrollbars=no, resizable=no, 
     location=no, directories=no, status=no');

        window.location = '/My_Folder/PHP/file_2.php';
     }
     </script>

Of all these, none are working.

But (b) is the best solution so far, because, at least, it opens the New (Child) Window, as it should. But, it still does not re-direct the Parent Window :(((

phpnewbie2015
  • 366
  • 2
  • 4
  • 17
  • I don't know much JavaScript, but shouldn't the `setTimeout` line come *inside* the function definition rather than after it? – dg99 May 01 '15 at 22:07

2 Answers2

1

Try this:

<script type="text/javascript">
function OpenWindow() { window.open('/My_Folder/file.php','newwindow',
             config='height=670,width=1400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
settimeout( function(){document.location.href='/My_Folder/PHP/file_2.php'}, 1000 );
}
</script>

Moves the settimeout into the function and uses it properly, and tells the window to change to a new location.

serverSentinel
  • 994
  • 6
  • 20
  • Hmmm.............this didn't work. The new (child) window opened, as it should. But..........the Parent Window did not re-direct to the new location. – phpnewbie2015 May 02 '15 at 06:12
  • My apologies, it should be document.location.href='/...'; I'll edit the answer if it will let me. – serverSentinel May 02 '15 at 21:05
0

My javasrcipt isnt too hot, but does this not work ?

 <script type="text/javascript">
 function OpenWindow()    {
    window.open ('/My_Folder/new_file.php', 'newwindow', 
      config='height=670, width=1400,   
      toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, 
      directories=no, status=no');
     window.top.location.href = '/My_Folder/PHP/file_2.php'
     }


</script>
Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • Thanks Rohit. But, your code gave me a syntax error. Shouldn't there be brackets and a semi-colon somewhere here : '/My_Folder/PHP/file_2.php' ??? – phpnewbie2015 May 02 '15 at 06:17