Onbeforeunload not working in chrome version 80

Discussion in 'Javascript' started by newcoder, Feb 27, 2020.

  1. newcoder

    newcoder

    Joined:
    Feb 27, 2020
    Messages:
    2
    Likes Received:
    0
    Hi,

    I have a datatable on page and I have search functionality for the datatable on the page.when i try to search string it filters datatable. And when I redirect to another page and again come back to the same page the search filter(datatable ) retains.

    I have written down function on onbeforeunload event as below

    var unloadCatcher = function() {
    var dateObjAjax = new Date();
    var timestamp = dateObjAjax.getTime();
    var sortColumnIndex = $('#example').dataTable().fnSettings().aaSorting[0][0];
    var pageType = "EPPatientList";
    var paginationSize = $("#example_length select option:selected").prop('value');
    var sortDirection = $('#example').dataTable().fnSettings().aaSorting[0][1];
    var searchText = "";
    if ($('#search_input').is(':visible')) {
    searchText = $('#search_input').val();
    $("#hiddenSearchText").val(searchText);
    }
    else {
    $("#hiddenSearchText").val("");
    }

    $.ajax({
    url: "<%=userPreference%>&sortColumnIndex=" + sortColumnIndex
    + "&pageType=" + pageType
    + "&paginationSize=" + paginationSize
    + "&sortDirection=" + sortDirection
    + "&time="+timestamp,
    type: "post",
    data: $("#hiddenSearchForm").serialize(),
    cache: false,
    async: false,
    success: function(data){
    }
    });

    var otable = $('#example').DataTable();
    var pageSize = otable.page.info().length;

    var expdate = new Date();

    expdate.setTime(expdate.getTime() + (60 * 60 * 1000 * 24 * 365 * 20));
    $.cookie('SJM_PT_'+userLogonCookieName+'_PageSize',pageSize,{ expires: expdate });
    }

    window.onbeforeunload = unloadCatcher;

    currently this function (window.onbeforeunload = unloadCatcher;) doesn't work for me as I am using chrome 80.

    And as per my knowledge Chrome version 80 does not support window.onbeforeunload events any more instead there are two new calls fetch and sendBeacon is supported in Chrome and other browsers except IE11. So is there any alternative?

    Thanks in advance
     
    newcoder, Feb 27, 2020
    #1
    1. Advertisements

  2. newcoder

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    82
    Likes Received:
    10
    You are using either vue, react, or angular js along with jquery. You need to go to a forum that specializes in those frameworks. Each abomination has their own users forum and help center. Use google to look up where.
     
    sunfighter, Feb 27, 2020
    #2
    1. Advertisements

  3. newcoder

    newcoder

    Joined:
    Feb 27, 2020
    Messages:
    2
    Likes Received:
    0
    We are not using any framework.The application is in jquery and backend java
    Also we have used datatables to render data in table.
     
    Last edited: Mar 3, 2020
    newcoder, Mar 3, 2020
    #3
  4. newcoder

    sunfighter

    Joined:
    Nov 27, 2019
    Messages:
    82
    Likes Received:
    10
    "We are not using any framework.". That is what jquery is - a framework.
    I use Version 80.0.3987.122 (Official Build) (64-bit) and window.onbeforeunload is supported, but it is a fickle function and does not always work. The browser does not make a difference.
    I bow out; if you receive no help from my constituents try another forum.
     
    sunfighter, Mar 3, 2020
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.