How to play sound only once in HTML5?
Hi makenzi.exc,
Refer below example.
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> body { font-family: Arial; font-size: 10pt; } </style> </head> <body> <audio id="audio" controls onended="DisablePlay()"> <source src="https://www.aspsnippets.com/audio/welcome.mp3" type="audio/mpeg"> </audio> <script type="text/javascript"> var audioPlayed = false; function DisablePlay() { var audio = document.getElementById('audio'); if (!audioPlayed) { audio.controls = false; audioPlayed = true; } } </script> </body> </html>
Demo
Screenshot
Downloads
Download Sample
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.