1

I am working on web application where application will be opened in browsers on tablets . Application will be run on multiple tablets at a time. I want to know if there is any way by which I can uniquely identify the tablet on which application is running , basically something like device token?

alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
  • generate a random number on the first visit, save that to localStorage, send with requests. – dandavis Sep 26 '15 at 06:04
  • If your plan is get stats, then you can use google analytics, it will give you complete details of the devices your application is running on. – Sahil Sep 26 '15 at 06:10
  • Do you have a user login? – jfriend00 Sep 26 '15 at 06:13
  • Same questions here: http://stackoverflow.com/questions/3764115/can-i-retrieve-an-ipad-unique-device-identifier-that-through-safari-with-a-js-we and http://stackoverflow.com/questions/7089361/getting-ipad-device-information-using-safari-web-browser – jfriend00 Sep 26 '15 at 06:14
  • you can use font/canvas fingerprinting if you need to detect machines even after cookies/localStorage is cleared... – dandavis Sep 26 '15 at 06:28
  • @jfriend00 yes I do have user login – alwaysLearn Sep 28 '15 at 04:17
  • So, why don't you use the login cookie to uniquely identify each tablet then? – jfriend00 Sep 28 '15 at 04:20
  • I am looking for something that can persists even after logout.I dont want be dependent on user login , but want to have something that can uniquely identify the device – alwaysLearn Sep 28 '15 at 04:28

1 Answers1

0

Well ... This can be done but you risk duplicates in the long run to be honest. Here is how you can try to keep it as random as possible ->

This encodes a random set of digits, the userAgent and the Date in base64, but you should honestly be using something more reliable server side.

var id = btoa( Math.random() + navigator.userAgent + Date() );

Example Below ::

function id() {
  document.getElementById('code').insertAdjacentHTML('beforeend',( btoa( Math.random() + navigator.userAgent + Date() ) ) + '<br>' );
}
document.getElementById('click').addEventListener('click',id,false);
<input id='click' type='button' value='click'><br>
<div id='code'></div>
Jesse
  • 2,790
  • 1
  • 20
  • 36
  • do you know what the odds of a duplicate are with that code? – dandavis Sep 26 '15 at 06:26
  • A benchmark should be done, but the odds would be pretty low – Jesse Sep 26 '15 at 06:30
  • 1
    my point is don't talk down your solution: you have MUCH better odds of being both struck by lighting and winning the lotto on your birthday than you do of seeing a dupe... – dandavis Sep 26 '15 at 06:37