I'm tying to store fingerprint2 result in a var.
var info = {};
new Fingerprint2().get(function(result, ponents){
info.fingerprint = result;
});
alert(info.fingerprint);
but not work is there a better way like:
var fp = new Fingerprint2().get();
or some enhanced method?
edited : Modern & flexible browser fingerprinting library, a successor to the original fingerprintjs /
Usage:
new Fingerprint2().get(function(result, ponents){
console.log(result); //a hash, representing your device fingerprint
console.log(ponents); // an array of FP ponents
});
I'm tying to store fingerprint2 result in a var.
var info = {};
new Fingerprint2().get(function(result, ponents){
info.fingerprint = result;
});
alert(info.fingerprint);
but not work is there a better way like:
var fp = new Fingerprint2().get();
or some enhanced method?
edited : Modern & flexible browser fingerprinting library, a successor to the original fingerprintjs http://valve.github.io/fingerprintjs2/
Usage:
new Fingerprint2().get(function(result, ponents){
console.log(result); //a hash, representing your device fingerprint
console.log(ponents); // an array of FP ponents
});
Share
Improve this question
asked Sep 29, 2016 at 11:21
محمد علی پور فتحکوهیمحمد علی پور فتحکوهی
4135 silver badges20 bronze badges
1 Answer
Reset to default 10Your code is not working as expected because Fingerprint2().get(...)
is asynchronous - that means that alert(info.fingerprint)
will run before the callback function passed to get
has finished.
To understand why this is necessary if you don't understand the concept of asynchonicity, take a look at the demo page. You'll see that it says how long it takes to calculate the fingerprint. You alert
will be run between when get
is called and when the has been calculated, and therefore cannot know what the fingerprint will be.
The only time that you can guarantee that you have the fingerprint is during the callback function.
var info = {};
new Fingerprint2().get(function(result, ponents) {
info.fingerprint = result;
afterFingerprintIsCalculated();
});
function afterFingerprintIsCalculated() {
alert(info.fingerprint);
}
// BETTER (no global state)
new Fingerprint2().get(function(result, ponents) {
var info = {
fingerprint: result
};
processFingerprint(info);
});
function processFingerprint(data) {
alert(data.fingerprint);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743748557a4500469.html
评论列表(0条)