i have the following SweetAlert Code..
<script type="text/javascript" charset="utf-8">
$('.patient-details').click(function(e) {
e.preventDefault();
var name = $(this).attr('data-name');
var gender = $(this).attr('data-gender');
var age = $(this).attr('data-age');
var country = $(this).attr('data-country');
var state = $(this).attr('data-state');
var address = $(this).attr('data-address');
var report = $(this).attr('data-report');
swal({
title: name,
text: "Gender: " + gender +"\n" + "Age: " + age +"\n" + "Country: " + country +"\n" + "State: " + state +"\n" + "Address: " + address +"\n" + "Report: " + report,
confirmButtonColor: "#00B4B4",
imageUrl: "images/avatar/user.png",
});
});
</script>
The var report is a link and i need the link displayed in the modal. I tried html: true etc. html is no longer used. Instead use the content object. as doc says:
https://sweetalert.js.org/docs/#content
https://sweetalert.js.org/guides/
But i as a newbie is unable to make sense out of it.
Requesting help on how to display the link in the modal and the link to be opened in new window.
Update: Since the solutions provided were not working i used another approach using html to resolve it. Need to remove text, else text will be default. Codepen link: https://codepen.io/pamela123/pen/GOJZgo
If you are not still able to find a solution, I tried recreating the modal https://codepen.io/AJALACOMFORT/pen/zPGqNe?editors=0010
Hopefully it helps. (Note I did not use the same transition effect like in sweet alert, so adjust as you please)
You do not need to use the option "content" for a simple link in the text. The option "text" can only display pure text, no html. However, the option "html" can display html.
Not to be confused with the old version SweetAlert 1.X: There you had to set html = true.
In SeewtAlert2, the html is set directly in the "html" option. Do not use option "text" in this case.
Works fine in sweetAlert.version = '6.9.1';
Example of Jeremy Thille:
https://codepen.io/jeremythille/pen/wPazMw
As the doc says,
html
is deprecated and no longer works.They have replaced
html
withcontent
, which is not a string any longer, but an Object.This
content
object looks like this :So I guess you can build your own link like this :
...and then simply pass the
content
object toswal
:Note that this is untested, I'm not sure if
element:"a"
works. But anyway, the doc gives a better way :So you can create a link this way :
As an aside, you can heavily optimize the code you provided in your question by caching
$(this)
(which is expensive to create) and reuse it. Also,.attr("data-x")
has a shorthand,.data("x")
.OR even better :
which gives an object containing all your data attributes. Which you can then reach using :
Or in ES6 :)
Why not try the following (I have never used sweet alert, but after reading the documentation this is what I would try)
Or
hope that helps