Can anyone explain how can three events can be bind to same function ? i.e. same function should be called when the following events happen.
- window unload.
- on pressing 'ESC' button.
- on clicking 'close' class.
I have written function on clicking '.close' class in following way:
<script>
$(document).ready(function() {
var start = new Date().getTime();
var starttime = new Date(start);
$(".close").click(function () {
jwplayer('mediaplayer').stop();
end = new Date().getTime();
endtime = new Date(end);
$.ajax({
url: "/courses/136",
data: {'timeSpent': endtime - starttime},
});
});
});
</script>
The same thing should happen for window.unload()
and on pressing ESC button. Is there any Jquery method for this.
Create a function that is responsible for handling the events and then you just have to pass that function to every event you want to execute it.