0

I have a client(JavaScript) server(PHP) application using AJAX. On the AJAX request my PHP script returns some info to the client AND needs to open a separate browser tab as a separate process, asynchronously. How can I do that (exec, shell_exec, passthru ... don't work)?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ginger Opariti
  • 1,282
  • 5
  • 23
  • 41

4 Answers4

1

You cannot control this from server-side code. You would have to issue some javascript to the client, and have that JS code open the window/tab and point that window/tab at the URL which provides your data. Of course, you can just output the full page contents for this JS code to stuff into the window as well. But regardless, you cannot make the browser open a window directly from the server. At most you can suggest via some JS, or a target="..." attribute on a link or form.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

When you receive the info from the Ajax request, open a new tab using JavaScript.

Korvin Szanto
  • 4,531
  • 4
  • 19
  • 49
0

You can never, ever decide on the behaviour of client's browser. It's up to the user whether they want to open up a tab. Therefore, not only that you can't force tab opening, you shouldn't be able to do it in the first place.

N.B.
  • 13,688
  • 3
  • 45
  • 55
0

You just output it to the client side

<?php
echo '<script>window.open("http://addr.com", "_blank", "width=400,height=500")</script>';
genesis
  • 50,477
  • 20
  • 96
  • 125