Reputation: 1292
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)?
Upvotes: 0
Views: 6692
Reputation: 50974
You just output it to the client side
<?php
echo '<script>window.open("http://addr.com", "_blank", "width=400,height=500")</script>';
Upvotes: 0
Reputation: 4511
When you receive the info from the Ajax
request, open a new tab using JavaScript
.
Upvotes: 1
Reputation: 14081
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.
Upvotes: 0
Reputation: 360762
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.
Upvotes: 1