link 的 keycloak 翻译/消息应该在新标签中打开

keycloak translation / message with link should open in new Tab

我想在我的 messages_en.properties 中包含一个 link 的翻译,它会在新选项卡中打开。有办法吗?

我已经尝试添加

<a target="_blank" href="http://example.com">Example</a>

<a href="#" onclick='window.open("http://example.com");return false;'>Example</a>

没有成功。

提前致谢

您的 HTML 很可能因为模板文件中的 kcSanitize 而无法正常工作。在允许 HTML 消息的地方,Keycloak 的 FreeMarker 模板也将使用此方法包装文本:

Allows sanitizing of html that uses Freemarker ?no_esc. This way, html can be allowed but it is still cleaned up for safety. Tags and attributes deemed unsafe will be stripped out.

no_esc 允许 HTML 呈现(通过不转义)但 kcSanitize 首先去除不安全的标签和属性。在我的测试中,我发现“target”和“onclick”被删除了。

一种可行但出于安全考虑我不推荐的方法是删除相应 .ftl 文件中消息显示位置周围的 kcSanitize()。

另一个想法是向 .properties 文件中的元素添加一个 id 或 class,并使用自定义 Javascript 来设置 target="_blank" 属性。