Hi Guys,
This is is my code which i am using to add a hyperlink in the text .
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"
});
But it doesn't come out properly. Here is how it comes
Can you please let me know how can add an anchor tag inside the sweet alert.
Thanks
Adi
https://sweetalert.js.org/guides/#upgrading-from-1x
html is no longer used. Instead use the content object.
Hi @SergeyW ,
Thanks for your reply. Yeah when i researched a bit about it, I got to know about the same.
But unfortunately, I am not able to place a hyperlink in the alert box with content object also. I had searched for some examples and i got many of them but all are about adding HTML form elements, Buttons, etc and none about hyperlinks or anchor tags.
If you can show me how to add an anchor tags or may be share some examples similar to that, it would be great.
Thanks
Adi
Hey there,
The reason the html
parameter has been disabled is to discourage use cases where the website could potentially be XSS-attacked.
However, you should still be able to render raw HTML by passing a DOM node to the content
parameter, like this:
const el = document.createElement('div')
el.innerHTML = "Here's a <a href='http://google.com'>link</a>"
swal({
title: "Hello!",
content: el,
})
Thanks a lot @t4t5
Most helpful comment
Hey there,
The reason the
html
parameter has been disabled is to discourage use cases where the website could potentially be XSS-attacked.However, you should still be able to render raw HTML by passing a DOM node to the
content
parameter, like this: