簡體   English   中英

如何在無需登錄的情況下從訪問我的 web 頁面的每個用戶那里獲取唯一 ID?

[英]How to get an unique ID from every user visiting my web page without the need of login in?

我想要一個 Web 頁面並以某種方式識別每個訪問者。 也許使用他們的 MAC 地址。 是否可以在我的 web 頁面中獲取訪問者的 MAC 地址? 或者有沒有其他方法可以得到我想要的?

我不想制作登錄表單,因為我討厭 web 頁面要求我登錄或創建帳戶時,如果該頁面僅識別每種情況下使用的設備會更好。

謝謝你。

向用戶詢問他們的 MAC 地址會引發安全問題,我認為 JavaScript 不允許網頁訪問該信息。 不確定這是否符合您的目的,但如果用戶允許必要的權限,您可以獲取地理位置,然后創建一個唯一的 hash。 您可以在 MDN Web Docs 上找到詳細指南

function geoFindMe() {

  const status = document.querySelector('#status');
  const mapLink = document.querySelector('#map-link');

  mapLink.href = '';
  mapLink.textContent = '';

  function success(position) {
    const latitude  = position.coords.latitude;
    const longitude = position.coords.longitude;

    status.textContent = '';
    mapLink.href = `https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`;
    mapLink.textContent = `Latitude: ${latitude} °, Longitude: ${longitude} °`;
  }

  function error() {
    status.textContent = 'Unable to retrieve your location';
  }

  if(!navigator.geolocation) {
    status.textContent = 'Geolocation is not supported by your browser';
  } else {
    status.textContent = 'Locating…';
    navigator.geolocation.getCurrentPosition(success, error);
  }

}

document.querySelector('#find-me').addEventListener('click', geoFindMe);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM