Reputation: 75
Actually i tried to make a sweet alert when i press the button (Back to Home) but still i have troubles.
I use the fllowing syntax:
<a class="btn btn-info" style="background-color:blue" asp-controller="Home" onclick="return confirm('Are you sure you want to come back home?')">
<span class="material-icons">home</span> Back to Home
</a>
The above syntax works well, but i need to be more beatiful as sweet alert.
Please let me know your idea. I did many ways but it seems that some thing is wrong.
Upvotes: 0
Views: 1492
Reputation: 75
We solved the problem as following:
Actually in this case it is better to use button tag:
<div class="pb-1 pt-1 float-left">
<button class="btn btn-info" id="test">
<span class="material-icons">home</span> Back to Home
</button>
</div>
Then in a javscript file we attached the following sweet alert function:
$("#test").click(function () {
swal({
title: "Are you sure you go back to home?",
text: "You will not be able to recover your data!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: false
},
function () {
location.href = "/Home/Index";
});
});
And do not forget to attach the sweet alert library from the following links:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" />
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
or you can directly inculde the above links in _layout.cshtml file, then it will be available for all the WebApp.
I hope it will be useful for others.
Upvotes: 1