JavaScript 唯一浏览器 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4935964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript Unique Browser Id
提问by Ozzy
is there anyway to create a unique ID for a browser within javascript?
无论如何要在javascript中为浏览器创建一个唯一的ID?
Im not talking about an ID that is random everytime it is generated but an ID that is unique to the browser it is generated in but also takes into account the computer its running on.
我不是在谈论每次生成时都是随机的 ID,而是一个 ID,它对于生成它的浏览器是唯一的,但也考虑到它运行的计算机。
Example:
例子:
Windows 7 Chrome might generate: asdh128hakj4gh
Windows 7 Chrome 可能会生成:asdh128hakj4gh
Windows 7 Opera might generate: 23hjad823hjakk
Windows 7 Opera 可能会生成:23hjad823hjakk
Windows 7 Chrome, diff hardware, might generate: asd238881jaal
Windows 7 Chrome,差异硬件,可能会生成:asd238881jaal
etc...
等等...
Is there anyway to do this?
有没有办法做到这一点?
采纳答案by IProblemFactory
Use cookies
and some unique hash into its. (Each browser has own cookie jar, even if on computer is many browsers)
使用cookies
和一些独特的散列到它的。(每个浏览器都有自己的cookie jar,即使电脑上有很多浏览器)
回答by Makubex
What you are looking for is called Browser Fingerprinting.
您正在寻找的是所谓的浏览器指纹。
You can google for some open source libraries. Ex: fingerprintjs2
你可以谷歌一些开源库。例如:指纹js2
Check out EFF's demo
查看EFF 的演示
回答by Bill
How about the MD5 of the UserAgent + ClientIP + 'extrasalt'?
UserAgent + ClientIP + 'extrasalt' 的 MD5 怎么样?
That will get you close but not perfect because it is possible for 2 clients to have the same IP (using NAT) and exact same UserAgent (tightly controlled IT department = same deployment, or just luck).
这将使您接近但并不完美,因为 2 个客户端可能具有相同的 IP(使用 NAT)和完全相同的 UserAgent(严格控制的 IT 部门 = 相同的部署,或者只是运气)。
回答by Jaycee
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) document.write('IE: ' + Sys.ie);
if (Sys.firefox) document.write('Firefox: ' + Sys.firefox);
if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
if (Sys.opera) document.write('Opera: ' + Sys.opera);
if (Sys.safari) document.write('Safari: ' + Sys.safari);
With these code you can get the type and the version of the browser, and the value should be unique according to different browser , if you want to generate other unique ID base on it , then use it
通过这些代码可以得到浏览器的类型和版本,并且根据不同的浏览器该值应该是唯一的,如果你想根据它生成其他唯一的ID,然后使用它
回答by Scott
What it looks like you are trying to do is some kind of licensing? So that only so many browsers can be registered to use your app?
看起来您正在尝试做的是某种许可?所以只能注册这么多浏览器才能使用您的应用程序?
Unfortunately there is no way of reading the users computer hardware setup. As one answer says you can store a cookie on the machine but it can easily go missing.
不幸的是,无法读取用户的计算机硬件设置。正如一个答案所说,您可以在机器上存储一个 cookie,但它很容易丢失。
If you were restricted to using old IE browsers you could use ActiveX to read computer hardware: http://www.devarticles.com/c/a/JavaScript/How-to-Use-JavaScript-for-Hardware-Knowledge/
如果您被限制使用旧的 IE 浏览器,您可以使用 ActiveX 来读取计算机硬件:http: //www.devarticles.com/c/a/JavaScript/How-to-Use-JavaScript-for-Hardware-Knowledge/
回答by Aslan Muhammad-Rza
You can use biri library. The ID is generated per computer, and doesn't change unless the MAC address of the computer changes.
您可以使用biri 库。ID 是每台计算机生成的,除非计算机的 MAC 地址发生更改,否则不会更改。