【问题标题】:Is there any way to open link in anew tab from inner html (angular 6)有没有办法从innerhtml(角度6)在新标签中打开链接
【发布时间】:2020-05-07 14:54:50
【问题描述】:

我有一个像这样的内部 html 的 span 标签

在我的 html 中:

<span [innerHTML]="description"></span>

在我的 ts 中:

description = "some random text  https://stackoverflow.com/ Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"

它会显示链接,但是当我单击该链接时,它会在同一个选项卡中打开,但我希望它在新选项卡中打开。

有什么办法吗?

【问题讨论】:

    标签: html angular innerhtml


    【解决方案1】:

    在这种情况下,您使用的是 innerHtml 属性绑定,您可以在描述文本中放置 html link 并使用 target="_blank" 在新选项卡中打开链接:

    description =
        'some random text <a href="https://stackoverflow.com" target="_blank">https://stackoverflow.com/</a> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s';
    

    【讨论】:

      猜你喜欢
      • 2019-02-13
      • 1970-01-01
      • 1970-01-01
      • 2020-08-09
      • 2021-09-26
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多