前端设备指纹的生成,可使用fingerprintjs2

github地址: https://github.com/Valve/fingerprintjs2

 

demo:

// 初始化(options: 可设置需要忽略掉的特征属性, callback: 回调方法)
new Fingerprint2({excludeHasLiedBrowser: true, excludeIndexedDB: true,excludeUserAgent: true, excludeJsFonts: true, customFunction: function(){
    // 获取浏览器所在机器操作系统版本
    var u = navigator.userAgent,version = \'\';
    if (u.indexOf(\'Mac OS X\') > -1) {
        //ios
        var regStr_saf = /OS [\d._]*/gi;
        var verinfo = u.match(regStr_saf);
        version = (verinfo + "").replace(/[^0-9|_.]/ig,\'\').replace(/_/ig,\'.\');
    } else if (u.indexOf(\'Android\') > -1
        || u.indexOf(\'Linux\') > -1) {
        //android
        version = u.substr(u.indexOf(\'Android\') + 8, u.indexOf(";", u.indexOf("Android")) - u.indexOf(\'Android\') - 8);
    } else if (u.indexOf(\'BB10\') > -1) {
        //黑莓bb10系统
        version = u.substr(u.indexOf(\'BB10\') + 5, u.indexOf(";", u.indexOf("BB10")) - u.indexOf(\'BB10\') - 5);
    } else if (u.indexOf(\'IEMobile\')) {
        //windows phone
        version = u.substr(u.indexOf(\'IEMobile\') + 9, u.indexOf(";", u.indexOf("IEMobile")) - u.indexOf(\'IEMobile\') - 9);
    }
    return version;
  }}).get(function(result, components){
    console.log(result); //a hash, representing your device fingerprint
    console.log(components); // an array of FP components
    document.getElementById(\'ua\').innerHTML = \'<p>hash:</p><p>\'+ result +\'</p>\'
  });

 

版权声明:本文为mjian原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/mjian/p/9250093.html