【发布时间】:2018-05-11 07:04:34
【问题描述】:
我在我的项目中使用sanitize-html。假设我收到一封带有锚标签的邮件,如下所示:
this is to test something <a href="https://www.google.com/">open google</a>
这封邮件出现在我的邮箱中,如下所示:
this is to test something open google
在同一标签中打开 google.com。但是我需要在新标签页中打开。 这是我的代码。
__html = sanitizeHTML(children, {
allowedTags: sanitizeHTML.defaults.allowedTags.concat([ 'img' ]),
allowedAttributes: {
'*': [ 'href', 'align', 'alt', 'center', 'bgcolor', 'style', 'width' ],
'img': ['src'],
'a' : ['target']
},
}
在这里我想设置或覆盖 target = "_blank" 。如何在sanitize-html 中实现这一点?
很遗憾,我找不到 sanitize-html 的标签。
【问题讨论】:
-
您是否尝试将
'a'添加到'*': ['a', 'href', 'align', 'alt', 'center', 'bgcolor', 'style', 'width']并尝试使用transformTags?
标签: javascript html dom