Sweetalert: 无法在甜蜜警报中添加超链接

创建于 2018-06-27  ·  4评论  ·  资料来源: t4t5/sweetalert

嗨,大家好,
这是我用来在文本中添加超链接的代码。
swal({ title: 'This is the ', text: '<a href="http://www.externalwebsite.com" target="_blank">externalwebsite.com</a>', html: true, showCancelButton: true, allowOutsideClick: true, goToExternal: true, externalUrl: 'http://www.externalwebsite.com', confirmButtonText: "Continue" });

但它不能正常输出。 它是这样来的

screenshot_32

你能告诉我如何在甜蜜警报中添加锚标签。

谢谢
阿迪

最有用的评论

嘿,

html参数被禁用的原因是为了阻止网站可能受到 XSS 攻击的用例。

但是,您仍然应该能够通过将 DOM 节点传递给content参数来呈现原始 HTML,如下所示:

const el = document.createElement('div')
el.innerHTML = "Here's a <a href='http://google.com'>link</a>"

swal({
  title: "Hello!",
  content: el,
})

所有4条评论

https://sweetalert.js.org/guides/#upgrading -from-1x
html 不再使用。 而是使用内容对象。

@SergeyW
感谢您的回复。 是的,当我对此进行一些研究时,我就知道了。

但不幸的是,我也无法在带有内容对象的警报框中放置超链接。 我搜索了一些例子,我得到了很多,但都是关于添加 HTML 表单元素、按钮等,而没有关于超链接或锚标记。
如果你能告诉我如何添加一个锚标签,或者可以分享一些类似的例子,那就太好了。

谢谢
阿迪

嘿,

html参数被禁用的原因是为了阻止网站可能受到 XSS 攻击的用例。

但是,您仍然应该能够通过将 DOM 节点传递给content参数来呈现原始 HTML,如下所示:

const el = document.createElement('div')
el.innerHTML = "Here's a <a href='http://google.com'>link</a>"

swal({
  title: "Hello!",
  content: el,
})

非常感谢@t4t5

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

jamieson99 picture jamieson99  ·  3评论

vmitchell85 picture vmitchell85  ·  6评论

Untit1ed picture Untit1ed  ·  5评论

sastrahost picture sastrahost  ·  5评论

mateuszjarzewski picture mateuszjarzewski  ·  4评论