Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="/tests/SimpleTest/EventUtils.js"></script>
<title>Test window for top navigation with user activation</title>
<script>
function navigate(aURL) {
try {
top.location.href = aURL;
} catch (e) {
top.postMessage("BLOCKED", "*");
}
}
window.onmessage = (e) => {
SpecialPowers.wrap(document).clearUserGestureActivation();
let [command, url] = e.data;
if (command == "CLICK") {
let button = document.querySelector("button");
button.addEventListener("click", () => {
navigate(url);
}, { once: true });
synthesizeMouseAtCenter(button, {});
} else if (command == "SCRIPT") {
navigate(url);
}
};
</script>
</head>
<body><button>Click</button></body>
</html>