t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.84k forks source link

Not able to Add a hyperlink in the sweet alert #845

Closed adiwithadidas closed 6 years ago

adiwithadidas commented 6 years ago

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

screenshot_32

Can you please let me know how can add an anchor tag inside the sweet alert.

Thanks Adi

SergeyW commented 6 years ago

https://sweetalert.js.org/guides/#upgrading-from-1x html is no longer used. Instead use the content object.

adiwithadidas commented 6 years ago

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

t4t5 commented 6 years ago

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,
})
adiwithadidas commented 6 years ago

Thanks a lot @t4t5

PrasaddTelemerge commented 3 years ago

Thank you so much @t4t5

gupta-sudo commented 2 years ago

Thank you

sangeethseeroo commented 2 years ago

Thanks @t4t5