当我在 iframe 中的页面上请求存储访问权限时,它返回“未定义”。
这意味着什么?我希望得到一个真实的,并且会理解错误。(被拒绝)但是在这种情况下未定义是什么意思?什么地方出了错?
<button id="start-button">Start Puctto</button>
<script>
function gain_access() {
document.cookie = "foo=bar"; // set a cookie
document.hasStorageAccess().then(hasAccess => {
if (!hasAccess) {
return document.requestStorageAccess();
}
}).then(_ => {
// Now we have first-party storage access!
// Let's access some items from the first-party cookie jar
document.cookie = "foo=bar"; // set a cookie
localStorage.setItem("username", "John"); // access a localStorage entry
window.opener.postMessage('set_session', '*');
window.location.href = document.referrer;
}).catch(_ => {
alert(_);
});
}
document.getElementById('start-button').addEventListener('click', function (){
console.log('Start button clicked');
gain_access();
})
</script>