js获取用户的IP地址,浏览器的相关信息,以及用户停留时间。
1,Default.aspx
2,JS.js
var fromURL;
var IP = returnCitySN["cip"];
var city = returnCitySN["cname"];
var Browse;
window.onload = function () {
fromURL = window.document.referrer;
if (fromURL == "") {
fromURL = "NOFromSource";
}
}
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox/([d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome/([d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version/([d.]+).*safari/)) ? Sys.safari = s[1] : 0;
/*测试*/
if (Sys.ie) Browse = 'IE: ' + Sys.ie;
if (Sys.firefox) Browse = 'Firefox: ' + Sys.firefox;
if (Sys.chrome) Browse = 'Chrome: ' + Sys.chrome;
if (Sys.opera) Browse = 'Opera: ' + Sys.opera;
if (Sys.safari) Browse = 'Safari: ' + Sys.safari;
if (Sys.ie == 6.0) { Browse = 'IE: ' + Sys.ie }
var start = new Date();
var time;
window.onbeforeunload = function () {
var end = new Date();
time = end.getTime() - start.getTime();
time = time / 1000;
$(function () {
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebService.asmx/Receive",
data: "{IP:'" + IP + "',city:'" + city + "',fromURL:'" + fromURL + "',Browse:'" + Browse + "',time:'" + time + "'}",
dataType: 'json',
success: function (result) {
//window.document.write(result.d);
}
});
});
return ;
};
3,web.config
4,webService.cs