借助新浪IP地址库,显示本地城市名称:
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" type="text/ecmascript"></script>
remote_ip_info.country
remote_ip_info.province
remote_ip_info.city
获取客户端IP:
<script type="text/javascript" src="http://www.coding123.net/getip.ashx?js=1"></script>
获取用户的访问开始时间、访问结束时间、以及用户与网站的交互时间(当用户在网页无操作时间超过30秒,理解为离开网页),其中无操作包括:鼠标点击、移动、滑轮无操作,键盘无按键操作。
var start = new Date();
var strStart = start.getFullYear()+"-"+(start.getMonth()+1)+"-"+start.getDate()+" "+
start.getHours()+":"+start.getMinutes()+":"+start.getSeconds();
var len = 0;
var end;
var status = "in";
var second = 30;
function revive(){
if(status == "out"){
start = new Date();
status = "in";
}
second = 30;
}
window.setInterval(function(){
second -= 1;
if(0 == second){
end = new Date();
len += (end.getTime() - start.getTime())/1000;
status = "out";
}
},1000);
$(‘body‘).click(function(){
revive();
});
$(‘body‘).mousedown(function(){
revive();
});
$(‘body‘).mouseup(function(){
revive();
});
$(‘body‘).mousemove(function(){
revive();
});
//(Firefox)
$(‘body‘).bind(‘DOMMouseScroll‘, function() {
revive();
});
//(IE,Google)
$(‘body‘).bind(‘mousewheel‘,function(){
revive();
});
$(‘body‘).keydown(function(e){
revive();
});
$(‘body‘).keyup(function(e){
revive();
});
$(‘body‘).keypress(function(e){
revive();
});
window.onbeforeunload = function(){
end = new Date();
var strEnd = end.getFullYear()+"-"+(end.getMonth()+1)+"-"+end.getDate()+" "+
end.getHours()+":"+end.getMinutes()+":"+end.getSeconds();
len += (end.getTime() - start.getTime())/1000;
var img = new Image();
img.src = contextPath + "behavior?stayTime=" + len + "&strStart" + strStart + "&lastDate=" + strEnd;
};
获取点击按钮:
<a onclick="return getid(this.id)"> 按钮</a>
function getid(id) {
var img = new Image();
img.src = contextPath + "button?id=" + id;
}