javascript - 如何在无需登录的情况下从访问我网页的每个用户那里获取唯一 ID?
问题描述
我想要一个网页并以某种方式识别每个访问者。也许使用他们的 MAC 地址。是否可以在我的网页中获取访问者的 MAC 地址?或者有没有其他方法可以得到我想要的?
我不想制作登录表单,因为我讨厌网页要求我登录或创建帐户时,如果该页面仅识别每种情况下使用的设备会更好。
谢谢你。
解决方案
向用户询问他们的 MAC 地址会引发安全问题,我认为 JavaScript 不允许网页访问该信息。不确定这是否符合您的目的,但如果用户允许必要的权限,您可以获取地理位置,然后创建一个唯一的哈希。您可以在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);
推荐阅读
- python - SQLAlchemy“'None'没有属性'label'”
- c# - 我在表达式中检查的数组值是否存储在表达式中
>? - typeorm - 可以将 typeORM 与 Druid 一起使用吗?
- python - 使用 PIL 在 python 中打开图像时,“模块”对象不可调用
- c++ - GStreamer 与 WebRTC、OpenCV-Server-Client
- groovy - Groovy DSL 比较字符串
- flutter - Flutter:签署应用程序问题,在 key.properties 上添加使用 Xamarin 开发的应用程序 v.1 中的先前密钥库抛出异常
- vim - 如何在 neovim 中移动页面和半页(默认键对我不起作用)
- android - B2C平台安卓回复网址
- php - 按数组键名手动重新排序多维数组