word and the following JavaS"> How to automatically play sound on mouse enter event without clicking on document?-PHP Chinese Network Q&A
How to automatically play sound on mouse enter event without clicking on document?
P粉744831602
P粉744831602 2023-09-02 00:21:32
0
1
576

I have the following HTML code:

word

and the following JavaScript/jQuery code:

$('#word').mouseenter(function() { var audio = $("#player")[0]; audio.load(); audio.play(); });

On my browser, this code only works if I click the document. Otherwise, it does not work and the following error appears in the JavaScript console:

Uncaught (in promise) DOMException: Play method not allowed The user agent or platform in the current context, possibly Because the user denied permission.

and the following warning:

Allow autoplay only if user accepts, The user has interacted with the website or the media file has the volume set Return to zero.

If I set the volume to zero, I get the following error:

Uncaught (in promise) DOMException: Media retrieval process The user agent terminated the resource at the user's request.

I tried it on both Chrome and Firefox.

P粉744831602
P粉744831602

reply all (1)
P粉635509719
word
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!