在 PHP echo 语句的新选项卡中打开链接

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

Opening a link in a new tab in a PHP echo statement

phphtml

提问by user1662306

Relatively new to PHP and I am uingd PHP to produce a table that is populated with records from a Database, and have a column in the 'echo' table which is a hyperlink. Is there a simple way in which i could get the link to open a new browser tab once clicked? Relevant code is below...

PHP 相对较新,我正在使用 PHP 生成一个表,该表由数据库中的记录填充,并在“echo”表中有一列是超链接。有没有一种简单的方法可以让我获得点击后打开新浏览器标签的链接?相关代码如下...

echo "<tr align = center bgcolor=white><td><b><a href=view_rfp_detail.php?sna=$sna >$sna</a></b></td><td>$ques</a></td><td>$ans</a></td>"; 

Thanks

谢谢

回答by Wearybands

If you want to open a new tab try target = blank in anchor tab

如果您想打开一个新标签,请在锚标签中尝试 target = blank

<a target = '_blank' href=view_rfp_detail.php?sna=$sna >$sna</a>

回答by xdazz

Add target="_blank"into your a tag.

添加target="_blank"到您的标签中。

回答by j08691

You could do:

你可以这样做:

echo "<tr align = center bgcolor=white><td><b><a target=\"_blank\" href=view_rfp_detail.php?sna=$sna >$sna</a></b></td><td>$ques</a></td><td>$ans</a></td>";

However based on how the user has their browser configured, this may open the link in a new tab or a new window.

但是,根据用户配置浏览器的方式,这可能会在新选项卡或新窗口中打开链接。

回答by Felix

echo <<<TR
<tr style="text-align: center; background: white">
  <td>
    <strong><a href="view_rfp_detail.php?sna={$sna}" target="_blank">{$sna}</a></strong>
  </td>
  <td>{$ques}</td>
  <td>{$ans}</td>
</tr>
TR

FTFY

FTFY

回答by Stephen

You could also use javascript which provides the same functionality and gets round strict validation errors.

您还可以使用提供相同功能并绕过严格验证错误的 javascript。

<a onclick="window.open(this.href); return false;" href=view_rfp_detail.php?sna=$sna >$sna</a>