sendbeacon

Event onbeforeunload isn't fired in Chrome Incognito

冷暖自知 提交于 2021-02-08 15:12:37
问题 I've been trying to send a beacon on beforeunload and it seems to work on pretty much all modern browsers, except Chrome in incognito mode. This is the code that works in all modern browsers, except Chrome in incognito mode: window.onbeforeunload = function() { navigator.sendBeacon("url"); } Not even this code doesn't seem to work: window.onbeforeunload = function() { console.log('before unload') } Am I doing anything wrong or is it just Chrome's fault? 回答1: What's your setup (SO, Chrome

Perform an asynchronous service get when closing browser window / tab with Angular

回眸只為那壹抹淺笑 提交于 2019-12-21 20:34:07
问题 I'm currently trying to make an Angular app make an API service call when the user tries to navigate away from my page. Either by closing the tab / window, or typing in an external URL. I've tried to implement several different ways I've seen described here on stackoverflow questions, but none seem to have the desired effect. Some mention sync ajax requests which have been, or are in the process of being deprecated in onbeforeunload on Chrome. Others advise the use of XMLHttpRequests, which