php 如何用 target='_blank' 打开一个新窗口?我的代码不起作用

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

How to open a new window with target='_blank' ? My code doesn't work

phphtmllayout

提问by Steven

$html=<<<html
<tr><td>$i.<a href="offtask.php?taskid=$taskid target='_blank' ">$title</a></td><td>$count</td><td class="nowrap">$locationtext</td></tr>
html;
echo $html;

How to open a new window in the code above? target='_blank'doesn't work.

如何在上面的代码中打开一个新窗口?target='_blank'不起作用。

回答by Asaph

Your targetattribute is stuck inside your hrefattribute. Try this:

你的target属性卡在你的href属性里面。尝试这个:

$html=<<<html
<tr><td>$i.<a href="offtask.php?taskid=$taskid" target="_blank">$title</a></td><td>$count</td><td class="nowrap">$locationtext</td></tr>
html;
echo $html;

回答by Marius

look at the code output by that code. It will look like this:

查看该代码输出的代码。它看起来像这样:

<tr><td>$i.<a href="offtask.php?taskid=$taskid target='_blank' ">$title</a></td><td>$count</td><td class="nowrap">$locationtext</td></tr>

and you want it to be

你希望它是

<tr><td>$i.<a href="offtask.php?taskid=$taskid" target="_blank">$title</a></td><td>$count</td><td class="nowrap">$locationtext</td></tr>

That is:

那是:

<a href="url" target="_blank">link</a>

回答by zombat

The reason it's not working is because you haven't separated your link attributes properly. Try outputting the hrefand the targetwith proper separation (ie, close your quotes).

它不起作用的原因是因为您没有正确分离链接属性。尝试以适当的分隔输出 thehref和 the target(即关闭引号)。

Use this:

用这个:

<a href="offtask.php?taskid=$taskid" target='_blank'>

instead of

代替

<a href="offtask.php?taskid=$taskid target='_blank' ">

回答by GrayWizardx

<a href="offtask.php?taskid=$taskid" target="_blank">

回答by user54542

I have tried putting the target="_blank" in a number of places, this code comes from a rss reader but I don't want people to click and leave my site but to just open another tab

我试过把 target="_blank" 放在很多地方,这个代码来自一个 rss 阅读器,但我不希望人们点击并离开我的网站,而只是打开另一个标签

if($linked ) $msg = '<a href="'.$link.'" class="srssfetcher-link">'.$msg.'</a>'; // Puts a link to the posts

if($linked ) $msg = '<a href="'.$link.'" class="srssfetcher-link">'.$msg.'</a>'; // Puts a link to the posts

回答by Anto Alexander

Use The target="_blank" in front of the href in php

在php中href前面使用target="_blank"