Jquery 无法跟踪已关闭选项卡的用户
我能够创建一个网站,在那里我能够计算有多少人滚动到页面的某个部分,以及有多少人被放入一个.txt文件。我一直在寻找,但我似乎不知道如何通过关闭或离开页面来跟踪有多少人离开了网站。 有人能帮我一下吗,因为我不知道我哪里出了问题 这是我的代码Jquery 无法跟踪已关闭选项卡的用户,jquery,Jquery,我能够创建一个网站,在那里我能够计算有多少人滚动到页面的某个部分,以及有多少人被放入一个.txt文件。我一直在寻找,但我似乎不知道如何通过关闭或离开页面来跟踪有多少人离开了网站。 有人能帮我一下吗,因为我不知道我哪里出了问题 这是我的代码 var hasScrolled = "blank"; $(window).scroll(function() { var y_scroll_pos = window.pageYOffset; if(isIE()<9 &&a
var hasScrolled = "blank";
$(window).scroll(function() {
var y_scroll_pos = window.pageYOffset;
if(isIE()<9 && isIE() != false){
var y_scroll_pos = document.body.scrollTop || document.documentElement.scrollTop;
}
if(y_scroll_pos > 200){
$(".header-inner").addClass("sticky");
$(".mazda-logo-left").addClass("sticky");
}else{
$(".header-inner").removeClass("sticky");
$(".mazda-logo-left").removeClass("sticky");
}
//console.log("hasScrolled" +hasScrolled)
$(".scrollpos").each(function(index, element) {
//$("body").append("#"+$(this).parent().attr("id"))
var scroll_pos_test = $("#"+$(this).parent().attr("id")).offset().top;
if(y_scroll_pos >= scroll_pos_test && y_scroll_pos < Number(scroll_pos_test)+$(this).parent().innerHeight()) {
if(hasScrolled != $(this).parent().attr("id")){
hasScrolled = $(this).parent().attr("id");
tracker($.trim(hasScrolled));
if ( hasScrolled == 'the-idea' ) {
//$(".wrapper").css("background","red")
$.getJSON('update_count.php?section=idea');
}
if ( hasScrolled == 'the-tech' ) {
//$(".wrapper").css("background","blue")
$.getJSON('update_count.php?section=tech');
}
if ( hasScrolled == 'the-result' ) {
//$(".wrapper").css("background","yellow")
$.getJSON('update_count.php?section=result');
}
}
}
});
});
$(".nav a").click(function(){
$(".nav a").removeClass("active");
$(this).addClass("active");
tracker($.trim($(this).attr("data-id")));
var dataCo = $(this).attr("data-id");
if ( dataCo == 'the-idea' ) {
$.getJSON('update_count.php?section=idea');
}
if ( dataCo == 'the-tech' ) {
$.getJSON('update_count.php?section=tech');
}
if ( dataCo == 'the-result' ) {
$.getJSON('update_count.php?section=result');
}
});
在不同的地方,比如在部分和标签前。就像在我的main.js中一样,你不能这样做。运行AJAX请求是异步的,如果在卸载事件中启动它,浏览器很可能会中止它,因为浏览器现在正在做的就是卸载页面。请记住,这不是您的浏览器,没有可靠的方法可以知道用户是否关闭/退出页面或关闭其浏览器。那么,您能否建议我可以做哪些与此相同的事情,或者类似的事情是否存在?
$( window ).unload(function() {
alert( "Bye now!" );
});