I want a web page to periodically check for some condition by connecting to a server.
If the condition occurs, it should post a notice, and play a sound.
In order to play the sound, there has to be some user interaction, so I ask the user
to click the page to get the whole thing going, which I call launching.
In order to repeatedly check for the condition, I need to refresh the page.
But that would require the user to click again (repeatedly), so I use an
iframe and refresh that. And it works.
However … in Firefox (only, apparently), if I refresh the parent page itself
(for whatever reason), then Firefox “helpfully” reloads the iframe automatically,
and does the launch right away. Then the sound doesn’t play.
I’m looking to avoid having to remember to do
a hard refresh on the parent page, or remembering to click after I do a soft
refresh, and haven’t found one. Chrome browser doesn’t do this, but I prefer
using Firefox.
Here is what I’ve tried, which isn’t working.
<script>
var launched = false;
function launch()
{
console.log("Launching: launched = " + launched);
if (!launched)
{
document.getElementById("framex").src = "checkalive1.shtml";
launched = true;
}
}
function virginstate()
{
console.log("virginstate called with launched = " + launched);
document.getElementById("framex").src = "";
launched = false;
}
</script>
<body onload="virginstate()" onclick="launch()">
<iframe id="framex" src=""> </iframe>
</body>
and in the browser console:
virginstate called with launched = false
Autoplay is only allowed when approved by the user,
the site is activated by the user, or media is muted.
checkalive1.shtml:168:7 Uncaught (in promise) DOMException:
The play method is not allowed by the user agent or the platform
in the current context, possibly because the user denied permission.