Showing posts with label beforeonunload. Show all posts
Showing posts with label beforeonunload. Show all posts

Sunday, 26 March 2017

How to call a function before leaving page - Jquery beforeonunload

Hi guys, Shraing Code Snippet for Calling a function before leaving page. It may be required for variety of purposes. you can use it to track statistics for user's leaving from a website page to record that page for bounce pages statistics from where user is leaving website mostly. this is just a simple example you can use it for variety of way.

you can share in comments for which purpose you may require this type of code functionality.

**Jquery Code Example -**

    $(window).bind('beforeunload', function(){
      Alert('Thanks And Bye!');

**Javascript Code Example -**

    // Anonymous function
    window.onbeforeunload = function(event) {
      var message = '';
      if (window.event) {
      event = event || window.event;
      event.preventDefault = true;
      event.cancelBubble = true;
      event.returnValue = message;