PHP 标头重定向到新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13482259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:32:43  来源:igfitidea点击:

PHP header redriction to new page

php

提问by user1509201

I would like to click on a hyperlink which will go to page 2, but I also want to open a new blank page.

我想单击将转到第 2 页的超链接,但我也想打开一个新的空白页。

I tried:

我试过:

header "Location: http://bing.com";
header ("Location: http://bing.com", false);
header ("Location: http://bing.com", true, 301);

I'd like to use only php to open the new blank page.

我只想使用 php 打开新的空白页面。

回答by Marcin Orlowski

You cannot do this from the header redirection. You need target="_blank"attribute added to your <A>in HTML. Or do the trick where your redirection redirects to the page that would use JavaScript to do that for you (expect it to be blocked by the browsers anti-popup feature though)

您不能从标头重定向中执行此操作。您需要在 HTML 中target="_blank"添加属性<A>。或者做一个技巧,让你的重定向重定向到使用 JavaScript 为你做的页面(尽管它会被浏览器的反弹出功能阻止)

回答by Jordan Mack

You cannot open a new window from doing a header redirection. You must use Javascript.

您无法通过执行标题重定向来打开新窗口。您必须使用 Javascript。

If you need to do it with PHP for some reason, you could print the Javascript like this:

如果出于某种原因需要使用 PHP 执行此操作,则可以像这样打印 Javascript:

<?php
echo '<script>window.open("http://www.google.com/");</script>';
?>

回答by Evert

This is not possible with PHP. If you want to open 2 pages at once (replace the current, and open a second tab/window) you must do this with javascript.

这在 PHP 中是不可能的。如果您想一次打开 2 个页面(替换当前页面,并打开第二个选项卡/窗口),您必须使用 javascript 执行此操作。

回答by Himanshu Goel

One of the perfect solution to it which I found here only and you can do one thing is that which page you want to open along with other one put the code below in a PHP page the one needs to be opened and this code will pop up for the link provided in place of default link.

我只在这里找到了它的完美解决方案之一,您可以做一件事是,您要打开哪个页面以及另一个页面,将下面的代码放在需要打开的 PHP 页面中,然后会弹出此代码对于代替默认链接提供的链接。

<?php
echo "<script type=\"text/javascript\">  window.open('http://reliable4you.com/', '_blank')  </script>";
?>

回答by Xtreme

This is my code for new tab and its working perfectly. Just only care about your file location.

这是我的新标签代码,它工作得很好。只关心您的文件位置。

CODE:

代码:

<?php 
          if(isset($_POST['button']))
             {
                echo '<script language="javascript">';
                 echo 'window.open( "/Projectfolder/File.php" )';
                 echo '</script>';
              }
          ?>