Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Thymeleaf to create links that open in a new window/tab

In basic HTML, a link can have the target="_blank" property to force it to open in a new window or tab. But if when I put that in an <a href> tag that also includes a th:href for Thymeleaf, Thymeleaf overwrites the whole tag and wipes out my target="_blank.

I've considered the brute force method of adding target="_blank" to every link as it is stored in my database so that it is already part of the link when Thymeleaf writes it out. But I would prefer a way to have Thymeleaf write the target="_blank" property as it is writing the <a> tag.

like image 266
cptully Avatar asked Oct 20 '16 02:10

cptully


1 Answers

Thymeleaf overwrites the a tag. Use th:target="_blank".

like image 120
kjsebastian Avatar answered Sep 24 '22 15:09

kjsebastian