PHP 标头在 _blank 中打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25527438/
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 17:52:25  来源:igfitidea点击:

PHP header opening in _blank

phpheaderanchor

提问by Mego

I use a header location to link another site at my site. Please, don't look after this manner, I can't do anything with it... My code looks like this

我使用标题位置链接我网站上的另一个网站。请不要照顾这种方式,我不能用它做任何事情......我的代码看起来像这样

if($navigateId==82) {
        header( "HTTP/1.1 301 Moved Permanently" ); 
        header( "Location: http://newsite.com/sample-link" ); 
    }

I would like, if I only can open this anchor at new card (target="_blank") Thanks for help

我想,如果我只能在新卡上打开这个锚点 (target="_blank") 谢谢你的帮助

回答by Rakesh Sharma

No it's not possible. header will simply redirect the current page, in the current window.

不,这是不可能的。header 将简单地重定向当前页面,在当前窗口中。

For this you need to use js like:-

为此,您需要使用 js,例如:-

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

For more :- Header Location in new tab

有关更多信息:-新选项卡中的标题位置

回答by Zeusarm

The thing is that you are using server-side redirection and the target="_blank" is client-side directive to browser to open the URL in new window (or tab). So I don't think that you can arrange it using server-side coding.

问题是您正在使用服务器端重定向,而 target="_blank" 是浏览器的客户端指令,用于在新窗口(或选项卡)中打开 URL。所以我不认为你可以使用服务器端编码来安排它。

BTW, I have found already this question answered - Header Location in new tab

顺便说一句,我发现已经回答了这个问题 -新标签中的标题位置

You can arrange needed functionality using jquery. I mean if the link which needs to be checked and opened in new window is not static html content or entered in a WYSIWYG you can check by AJAX call the id server-side and open it in new window if needed. The checkings can be done also client side but you have to supply the javascript code with the ID-s which need to be opened in new window.

您可以使用 jquery 安排所需的功能。我的意思是,如果需要在新窗口中检查和打开的链接不是静态 html 内容或在 WYSIWYG 中输入,您可以通过 AJAX 检查调用 id 服务器端并在需要时在新窗口中打开它。检查也可以在客户端完成,但您必须提供带有 ID-s 的 javascript 代码,这些 ID 需要在新窗口中打开。