There are many buttons and links that would let me quit one page. Before leaving this page to another, I want to ask something to the user, and then, just quit this page.
In our app, the "leave this page" is just like <canvas class="show"></canvas>
to <canvas class=""></canvas>
and showing another canvas. Others has done this. My goal is to detect whether the class="show"
is removed or not.
I have read this, this, and so on. I'm quite junior, do not understand what they really mean or just don't know how to implement it in my question.
Please help, the more specific example list below:
$('body').on('class_change_event', () => {
swal({
title: "Are you sure?",
text: 'If you close without saving, your changes will discarded.',
type: "warning",
showCancelButton: true,
confirmButtonText: "Save"
})
// After the user choose, do the original jobs
})
div.demo {
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<div class="demo">
<canvas class="load show"></canvas>
<canvas class="load"></canvas>
<canvas class="load"></canvas>
</div>
<a href="https://www.google.com">go to Google</a>
<a href="index.html">back to index</a>
<input type="button" value="Clear canvas" />
- Even when user click
button
ora
will causeclass="show"
changed. - I'm not sure if it's right to append event onto $('body')