使用Thymeleaf创建在新窗口/选项卡中打开的链接

7
在基本的HTML中,一个链接可以有target="_blank"属性来强制在新窗口或标签页中打开。但是,如果我把它放在一个同时包含Thymeleaf的<a href>标签内,Thymeleaf会覆盖整个标签并清除我的target="_blank"
我考虑了一种粗暴的方法,即在存储在数据库中的每个链接中添加target="_blank",这样当Thymeleaf输出时,它已经成为链接的一部分了。但我更希望有一种方法,在Thymeleaf编写<a>标签时,同时编写target="_blank"属性。

请尝试使用 th:target="_blank" - kjsebastian
谢谢@conscells。我会尝试的! - cptully
而且 th:target="_blank" 起作用了! - cptully
@MrLister 完成。 - kjsebastian
1个回答

15

Thymeleaf覆盖了a标记。使用th:target="_blank"


4
Full example <a th:href="@{https://MY-URL}" th:target="_blank"> - tw1742

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接