我正在操作一个按钮来撤销浏览器位置权限,在搜索过程中我发现"Permissions.revoke()“可以工作,但是在查看文档时我发现它是不可取的。我一直在搜索,却找不到类似的东西,我能用什么来做同样的事情呢?
这是我用的台词:
function toggleLocation() {
navigator.permissions.query({ name: 'geolocation'
}).then((result) => {
if (result.state === 'granted') {
navigator.permissions.revoke({ name: 'geolocation' });
$('#toggle_location').html('Turn location on');
} else if (result.state === 'prompt') {
navigator.permissions.request({ name: 'geolocation' });
$('#toggle_location').html('Turn location off');
} else if (result.state === 'denied') {
navigator.permissions.request({ name: 'geolocation' });
$('#toggle_location').html('Turn location off');
}
});
}发布于 2022-09-27 13:37:53
Permissions.revoke()
不再推荐
:不再推荐此特性。虽然有些浏览器可能仍然支持它,但它可能已经从相关的web标准中删除,可能正在被删除,或者可能仅为兼容性目的而保留。避免使用它,并在可能的情况下更新现有代码;请参阅本页底部的兼容性表,以指导您的决策。请注意,此功能可能在任何时候停止工作。
https://developer.mozilla.org/en-US/docs/Web/API/Permissions/revoke
https://stackoverflow.com/questions/73868343
复制相似问题