JavaScript get page load time and page dwell time

JavaScript get page load time and page dwell time

var duration = 0; //停留时间
var loadingTime = 0; //加载时间
var startTime = Math.ceil(new Date().getTime() / 1000);
window.onbeforeunload = function(e) {
    
     //停留时间
	duration = Math.ceil(new Date().getTime() / 1000) - startTime;
	console.log(duration)
};
window.onload = function(e) {
    
     //加载时间
	loadingTime = Math.ceil(new Date().getTime() / 1000) - startTime;
	console.log(loadingTime)
};

Guess you like

Origin blog.csdn.net/weixin_42436236/article/details/126240256