开发者

Open browser tab in php

开发者 https://www.devze.com 2023-04-06 13:55 出处:网络
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 separat

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)?


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


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.


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.


You just output it to the client side

<?php
echo '<script>window.open("http://addr.com", "_blank", "width=400,height=500")</script>';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号