有人知道如何使用等效的
<a href="test" target="_blank">
在php header()函数中
我需要在新标签中指导我的php页面。
答案 0 :(得分:3)
你做不到。 PHP无法控制浏览器。
你能做的最好的事情是:
echo '<script type="text/javascript">window.open(...);</script>';
但这可能会被弹出窗口阻止程序阻止。
或者,如果可能,您可以将启动的PHP请求本身设置为target="_blank"
。
答案 1 :(得分:2)
PHP是一种服务器端语言,不能用于执行客户端操作,即无法使用header()
重定向打开新窗口。它将始终重定向当前页面。如果您希望在新标签页中打开链接,则必须使用JavaScript。
例如:
<?php
echo "<script>window.open('http://www.example.com');</script>";
?>
但是,由于用户可能在其浏览器上安装了弹出窗口阻止程序,因此无法保证此功能。