获取设备类别及ip定位

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Dong8508/article/details/80538134
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script type="text/javascript">
        //document.write('IP地址:' + returnCitySN["cip"] + ', CID:' + returnCitySN["cid"] + ', 地区:' + returnCitySN["cname"]);
        var loginInfo = {};
        loginInfo.ip = returnCitySN["cip"];
        loginInfo.device = detectOS();
        function detectOS() {
            var sUserAgent = navigator.userAgent;
            var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
            if (isWin) return "Windows";
            var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
            if (isMac) return "Mac";
            var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
            if (isUnix) return "Unix";
            var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
            if (isLinux) return "Linux";
            return "None";
        }
       alert(JSON.stringify(loginInfo))
    </script>
</head>

<body>
</body>
</html>
备注:使用搜狐第三方IP定位接口,src指向地址需要根据生产域名调整,http协议就使用http引入,反之使用https引入。

使用场景:统计客户设备及区域分布。

展开阅读全文

没有更多推荐了,返回首页