问题描述
我想要一个网页并以某种方式识别每个访问者。也许使用他们的 MAC 地址。是否可以在我的网页中获取访问者的 MAC 地址?或者有什么其他方法可以得到我想要的东西?
我不想制作登录表单,因为我讨厌网页要求我登录或创建帐户,如果页面只标识每种情况下使用的设备会更好。
谢谢。
解决方法
向用户询问他们的 MAC 地址会引起安全问题,我认为 JavaScript 不允许网页访问该信息。不确定这是否符合您的目的,但如果用户允许必要的权限,您可以获取地理位置,然后创建一个唯一的哈希。您可以在 MDN Web Docs
上找到详细指南 herefunction 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);