javascript - Open child window and redirect parent window - Stack Overflow

I have a JavaScript that opens a new window when a button is clicked.It works fine.But, I want to r

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 :(((

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 :(((

Share Improve this question edited May 2, 2015 at 6:28 phpnewbie2015 asked May 1, 2015 at 21:19 phpnewbie2015phpnewbie2015 3762 gold badges5 silver badges17 bronze badges 1
  • I don't know much JavaScript, but shouldn't the setTimeout line e inside the function definition rather than after it? – dg99 Commented May 1, 2015 at 22:07
Add a ment  | 

2 Answers 2

Reset to default 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.

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745129775a4612907.html

相关推荐

  • javascript - Open child window and redirect parent window - Stack Overflow

    I have a JavaScript that opens a new window when a button is clicked.It works fine.But, I want to r

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信