Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 删除window.onbeforeunload调用,因为它不';我不支持Chrome80,我想使用fetch和sendBeacon_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 删除window.onbeforeunload调用,因为它不';我不支持Chrome80,我想使用fetch和sendBeacon

Javascript 删除window.onbeforeunload调用,因为它不';我不支持Chrome80,我想使用fetch和sendBeacon,javascript,jquery,ajax,Javascript,Jquery,Ajax,如果用户在搜索框中搜索页面中的某个文本,则通常使用window.onbeforeunload,该文本不再保留。因此,我们希望在除IE之外的所有浏览器中使用fetch或sendBeacon,而不是window.onbeforeunload 用于在serach框中搜索文本的代码段: <script type="text/javascript" charset="utf-8"> var unloadCatcher = function() { var da

如果用户在搜索框中搜索页面中的某个文本,则通常使用window.onbeforeunload,该文本不再保留。因此,我们希望在除IE之外的所有浏览器中使用fetch或sendBeacon,而不是window.onbeforeunload

用于在serach框中搜索文本的代码段:

<script type="text/javascript" charset="utf-8">

    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;

</script>

var unloadCatcher=函数(){
var dateObjAjax=新日期();
var timestamp=dateObjAjax.getTime();
var sortColumnIndex=$('#示例').dataTable().fnSettings().aaSorting[0][0];
var pageType=“EPPatientList”;
var paginationSize=$(“#示例#u长度选择选项:选定”).prop('value');
var sortDirection=$('#示例').dataTable().fnSettings().aaSorting[0][1];
var searchText=“”;
如果($('search_input')。是('visible')){
searchText=$(“#搜索输入”).val();
$(“#hiddenSearchText”).val(searchText);
}
否则{
$(“#hiddenSearchText”).val(“”);
}
$.ajax({
url:“&sortColumnIndex=“+sortColumnIndex
+“&pageType=“+pageType
+“&paginationSize=“+paginationSize”
+“&sortDirection=“+sortDirection
+“&time=“+时间戳,
类型:“post”,
数据:$(“#hiddenSearchForm”).serialize(),
cache:false,
async:false,
成功:功能(数据){
}
});
var-otable=$('#示例').DataTable();
var pageSize=otable.page.info().length;
var expdate=新日期();
setTime(expdate.getTime()+(60*60*1000*24*365*20));
$.cookie('SJM_PT_u'+userLogonCookieName+''u PageSize',PageSize,{expires:expdate});
}
window.onbeforeunload=unloadCatcher;

您是否尝试过这些替代方案?您是否遇到这些错误?任何联机选项都使用window.onbeforeuload事件中的navigator.sendBeacon调用。但我想删除这个。因此,我没有任何其他选择来使用sendBeacon并在Chrome 80中获取,而不是window.onbeforeunload