Skip to content

Instantly share code, notes, and snippets.

@Trikolon
Created September 24, 2021 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trikolon/531597cf73d88b23ae604e12a928aafc to your computer and use it in GitHub Desktop.
Save Trikolon/531597cf73d88b23ae604e12a928aafc to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>requestStorageAccess Frame</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<button id="btn">requestStorageAccess</button>
<button id="btn2">Open Window</button>
<script>
function openWindow() {
window.open("https://example.com");
}
document.getElementById("btn2").addEventListener("click", () => {
// Works
openWindow();
})
document.getElementById("btn").addEventListener("click", () => {
// Has user activation
document.requestStorageAccess().then(() => {
// User activation lost?
openWindow();
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment