Not able to Add a hyperlink in the sweet alert

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
t4t5commented, Jun 28, 2018

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,
})
0reactions
sangeethseeroocommented, Oct 21, 2021

Thanks @t4t5

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Sweet Alert and html link inside text - Stack Overflow
5 Answers 5 · Unfortunately it is not working. var link = document. · It must work. It's exactly what's written in the...
Read more >
How to add link in sweet alert? - Laracasts
I want to add 2 links in sweet alert. but I see this picture. alert()->warning("You must register now. ", 'OK')->html()->persistent("register.
Read more >
SweetAlert2 - a beautiful, responsive, customizable and ...
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
Read more >
Guides - SweetAlert
Showing an alert. After importing the files into your application, you can call the swal function (make sure it's called after the DOM...
Read more >
SweetAlert - UltraEdit
Download & install ; src · "lib/sweet-alert.min.js" ; script · link ; rel · "stylesheet" ; type · "text/css" ; href · "lib/sweet-alert.css" ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found