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

cpt*_*lly 4 html java thymeleaf

在基本HTML中,链接可以具有target="_blank"强制它在新窗口或选项卡中打开的属性.但是如果当我把它放在一个<a href>也包括一个th:hrefThymeleaf 的标签中时,Thymeleaf会覆盖整个标签并消灭掉我的标签target="_blank.

我已经考虑过将蛮力方法添加target="_blank"到每个链接中,因为它存储在我的数据库中,以便在Thymeleaf写出来时它已经是链接的一部分.但我更倾向于让Thymeleaf在target="_blank"编写<a>标签时写入属性.

kjs*_*ian 8

Thymeleaf会覆盖a标签.使用th:target="_blank".

  • 完整示例 `&lt;a th:href="@{https://MY-URL}" th:target="_blank"&gt;` (4认同)