javascript - 删除 window.onbeforeunload 调用,因为它在 Chrome 80 中不支持,而是我想使用 fetch 和 sendBeacon
问题描述
如果用户在搜索框中搜索页面内的文本,我们主要使用 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>
解决方案
推荐阅读
- highcharts - 如何消除高图区域样条图中的边距差距?
- amazon-web-services - AWS AutoScaling CoolDown 组件
- python-3.x - 如何将请求模块中的文件和表单参数传递给requests.request()?
- javascript - 从数组派生无序列表
- php - 如何在注册时将特定电子邮件域列入白名单
- ios - 将 NSSortDescriptor 与多个键和缺失数据一起使用
- spring-boot - JSESSIONID 安全标志-Spring boot 和 Spring Security(SAML)
- slack - Slack 机器人如何找到自己的 id?
- linker - 网站注册号以电话号码链接的形式出现,有没有办法逃脱?
- python - Selenium 的 XPath 问题