javascript - Send request on unload and/or beforeunload doesn't work on mobile? -
i know issue has been answered on cannot make work on mobile browsers.
i need send request server when web page closed (tab or window closed).
here do:
window.addeventlistener("unload",function(e) { var pl = "bla=blabla"; var req = new xmlhttprequest(); req.open("post","http://myapi/myendpoint",false); req.setrequestheader("content-type","application/x-www-form-urlencoded"); req.send(pl); },false); window.addeventlistener("beforeunload",function(e) { var pl = "bla=blabla"; var req = new xmlhttprequest(); req.open("post","http://myapi/myendpoint",false); req.setrequestheader("content-type","application/x-www-form-urlencoded"); req.send(pl); },false);
this works fine on desktop (chrome , firefox) if page either refreshed or tab/window closed.
on mobile, works when page refreshed or if enter url. it doesn't work if close tab or program (chrome/safari...). far, i've tested with:
- chrome on samsung s5 (android 4.4.2)
- default browser on samsung s5 (android 4.4.2)
- safari on ipad 3 (ios 8.0.2)
- chrome on ipad 3 (ios 8.0.2)
on mobile, request never sent if close tab :(!
how can make work on mobile well? (ie when page tab or browser closed/shut down) ?
Comments
Post a Comment