+ 30

[SOLVED] Can I play background music with confirm() in js?

When I try it normally it gives an error that play() function can only be initiated by user gesture... But I did kind of the same thing in this code of mine... but with swal alert https://code.sololearn.com/W153Wjsx8oFM/?ref=app

13th Dec 2020, 6:35 AM
Bartika🎶
Bartika🎶 - avatar
14 Answers
+ 19
From What I've seen, confirm is not counted as a user gesture. You need an event (touchstart,click etc) for that. Swal alert is actually an HTML element which you are clicking (user gesture).
13th Dec 2020, 1:04 PM
Nor'wester 🌪️ 🇧🇩 (INACTIVE)
Nor'wester 🌪️ 🇧🇩 (INACTIVE) - avatar
+ 11
Aravind maybe...
13th Dec 2020, 7:03 AM
Bartika🎶
Bartika🎶 - avatar
+ 11
Yes Atul🦚 bhaiya ... actually not feeling like creating a whole custom alert all by myself 😂🤣
13th Dec 2020, 1:26 PM
Bartika🎶
Bartika🎶 - avatar
+ 10
Bartika🎶 just create one in no time hardly take 1 hour and use in every code it will be ur signature alert too :)
13th Dec 2020, 1:28 PM
Atul
Atul - avatar
+ 8
Bartika🎶 u can make custom alert with js :D https://code.sololearn.com/WOaWO5tHdv8o/?ref=app confirm , alert aren't user gesture and Android don't allow autoplay of DOM elements
13th Dec 2020, 1:20 PM
Atul
Atul - avatar
+ 8
Atul🦚 1 hour !!!!! 😱
13th Dec 2020, 2:03 PM
Bartika🎶
Bartika🎶 - avatar
+ 7
Bartika🎶 Or.. You can just use Atul's confirm into ur code, 😂
13th Dec 2020, 1:51 PM
ASM
ASM - avatar
13th Dec 2020, 2:41 PM
Bartika🎶
Bartika🎶 - avatar
+ 6
Same error occured in my game, I guess it's sl issue! Isn't it?
13th Dec 2020, 6:58 AM
Aravind
Aravind - avatar
+ 2
Kode Krasher i agree with you but the whole point is autoplay here and that's not a " browser " issue its actually a "feature" of google ie android You can autoplay in Ios with some simple hacks but in android its not possible """ https://developers.google.com/web/updates/2016/07/autoplay """ You could read this And yeah i know about raw and dl i just wanted to demonstrate that custom alert thanks 😊 for pointing that out
14th Dec 2020, 12:33 PM
Atul
Atul - avatar
+ 2
Yes you can
14th Dec 2020, 6:53 PM
Ddhruv
Ddhruv - avatar
+ 1
Good
21st Oct 2024, 2:27 PM
AMAN KUMAR
AMAN KUMAR - avatar
- 3
ℍ𝕠𝕨 𝕔𝕒𝕟 𝕚 𝕞𝕒𝕜𝕖 𝕥𝕙𝕚𝕤 𝕗𝕠𝕣𝕞 𝕥𝕠 𝕥𝕣𝕒𝕟𝕤𝕗𝕖𝕣 𝕕𝕖𝕥𝕒𝕚𝕝𝕤 𝕥𝕠 𝕞𝕪 𝕘𝕞𝕒𝕚𝕝 𝕒𝕔𝕔𝕠𝕦𝕟𝕥.. https://code.sololearn.com/W4TeM9l6Oqi8/ Uzodimma Joseph Ifeanyi Ask by creating a new question. Do not hijack existing threads.
14th Dec 2020, 2:31 PM
Uzodimma Joseph Ifeanyi
Uzodimma Joseph Ifeanyi - avatar