i'm having a very strange issue here
i want to display an alert with javascript with an audio looping on the background
i managed to do it but it won't work in Chrome
it works perfectly in Firefox, Edge, IE but not Chrome -_-
in chrome the audio is looping only when you clic OK on the alert
Here is the code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="popup alert">
<title>This is a popup alert</title>
<style type="text/css">
body
{
background-image: url('image.png');
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<div align="center" id="text">
<h1>title text</h1>
<br>
<h1>title 2 text 2</h1>
<iframe src="silence.mp3" allow="autoplay" id="audio"
style="display:none"></iframe>
<audio controls autoplay loop style="display:none">
<source src="0564.ogg" type="audio/ogg">
</audio>
</div>
<script type="text/javascript">
function popup()
{
window.alert("Hello");
}
window.onload = setTimeout("popup()", 500);
</script>
</body>
</html>
Can you tell me why Chrome is making it soooooo hard ?
thank you
It is simply not possible:
In chrome, an alert pauses all processes. With that being said it is impossible to play a sound while an alert is happening on chrome.
Thanks to MarsAndBack I now have this tip:
There is an alternative to make your own prompt.
so a jQuery alert will have the same issue with chrome ?
because i'm trying to do a jQuery alert and it's the same issue on my side ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.