如何在_blank模式下使用PHP标头

时间:2015-06-23 10:22:08

标签: php html

我想在_blank模式下使用PHP标头,但它不起作用;这是我的代码。

<?php
$g = $_POST['G'];
    if($g) {
    header("Location: http://www.softbazz.com/", "_blank");

}

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>



<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="submit" name="G" />

</form>
</body>
</html>

我的观点是这段代码可以完成我的工作。

header("Location: http://www.softbazz.com/", "_blank");

请帮帮我。谢谢。 如果您需要演示,请转到site

3 个答案:

答案 0 :(得分:2)

结合php和js来得到答案。如果$ g为真,这将打开一个新标签.Works 100%,在我的localhost中测试


    <?php

            $g = $_POST['G'];
            if($g) 
           {
             echo "<script>window.open(\"http://www.softbazz.com/\", '_blank');</script>";
           }

    ?>

答案 1 :(得分:1)

您正尝试在新窗口中重定向页面。但你不能这样做。 header()将在当前窗口中重定向。

但JavaScript可能会派上用场。

<script type="text/javascript">window.open('http://www.example.com');</script>

答案 2 :(得分:0)

在PHP中,您可能需要通过javascript

完成此操作
<script type="text/javascript">window.open('http://www.softbazz.com/',width=700,height=500, resizable=1, left=0, top=0');</script>