亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to return the access behavior to the background through ajax before the web page is closed? ?
天蓬老師
天蓬老師 2017-07-05 11:00:43
0
3
996

I want to ajax the collected access information to the server when the web page is closed. The existing code is roughly as follows, but it is not feasible in actual testing.

window.onbeforeunload=function(e){    
    visit_end=new Date();
    visit_long=((visit_end.getTime()-visit_start.getTime())/1000).toFixed(1);
    //此處省略以上采集的訪問(wèn)信息

    ajax_visit_info(); //在關(guān)閉網(wǎng)頁(yè)時(shí),調(diào)用ajax函數(shù)發(fā)送到后臺(tái)。
    //return confirm('你真的要關(guān)閉嗎?');     //不想加上這個(gè),看起來(lái)不友好。    
}

Actual test, the background did not receive it at all...! Egg! pain!

What is the method? ? Without affecting the friendliness...

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見(jiàn)證您的進(jìn)步~~

reply all(3)
滿(mǎn)天的星座

onbeforeunload is unreliable, some browsers do not support it, and they do not support asynchronous tasks in callbacks.

Service workers require modern browser support

So let’s trigger it based on other events

洪濤

Only Service Worker

扔個(gè)三星炸死你

This should be data reporting. You can take a look at the implementation of Baidu reporting

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template