Script pour lancé un son (musique) à une image

spacezen Messages postés 3 Statut Membre -  
spacezen Messages postés 3 Statut Membre -
Bonjour,

je cherche un code javascript pour lancé un son (musique) au clic sur une image

J'ai deja un code mais impossible de le faire fonctionné et je sais pas si est correcte :

Code HTML
<img src="img.jpg" id="TonImage">
<audio><source src="song.mp3" type="audio/mpeg"></audio>
<code>
Code JS
<code js>
$(document).ready(function(){
    $('#TonImage').click(function(){
        var song = $('audio');
        if(song.paused){ 
            song.play()
        } else {
            song.pause()
        }
    })
})


EDIT : Ajout des balises de code

1 réponse

  1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
     
    Bonjour,

    Pour commencer... as tu bien chargé jquery dans ta page ?
    ensuite, as tu des messages d'erreur dans la console de ton navigateur ?

    0
    1. spacezen Messages postés 3 Statut Membre
       
      oui j'ai des erreurs
      0
    2. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
       
      Et tu penses que je vais le deviner ????
      Je suis bon.... mais pas encore devin. :-)
      0
    3. spacezen Messages postés 3 Statut Membre
       
      les erreurs:


      nsLoginManager:searchLogins: `formSubmitURL` or `httpRealm` is recommended nsLoginManager.js:407
      "Handler function NetworkEventActorProxy.addSecurityInfo threw an exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIMessageSender.sendAsyncMessage]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js :: NetworkEventActorProxy.methodFactory/< :: line 1656" data: no]
      Stack: NetworkEventActorProxy.methodFactory/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:1656:5
      exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
      NetworkResponseListener.prototype._getSecurityInfo<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:495:5
      exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
      onStartRequest@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:436:5
      Line: 1656, column: 0" ThreadSafeDevToolsUtils.js:80
      "Handler function NetworkEventActorProxy.addResponseContent threw an exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIMessageSender.sendAsyncMessage]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js :: NetworkEventActorProxy.methodFactory/< :: line 1656" data: no]
      Stack: NetworkEventActorProxy.methodFactory/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:1656:5
      exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
      _onComplete@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:620:5
      onStreamClose@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:577:7
      onInputStreamReady@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:668:7
      Line: 1656, column: 0" ThreadSafeDevToolsUtils.js:80
      PushDB:update: Ignoring invalid update ffccdf6a-aab7-4e11-88a5-e14e6496b21a null PushDB.jsm:399
      PushService:receivedPushMessage: Error notifying app AbortError PushService.jsm:764
      "Handler function threw an exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIHttpChannelInternal.remoteAddress]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js :: _onResponseHeader :: line 1331" data: no]
      Stack: _onResponseHeader@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:1331:5
      _dispatchActivity@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:973:9
      NetworkMonitor.prototype.observeActivity<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/webconsole/network-monitor.js:1035:7
      exports.makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://devtools/shared/ThreadSafeDevToolsUtils.js:101:14
      Line: 1331, column: 0" ThreadSafeDevToolsUtils.js:80
      La ressource à l’adresse « https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js%3E%3C/script%3E%20%20%20%3C/body%3E%3C/html%3E%3C/div%3E%3C/div%3E%3C/div%3E%3Cdiv%20class=col%20style=width:200px;margin-top:40px;%3E%3Cdiv%20class=component%20style=width:200px;%3E%3Cdiv%20class= » a été bloquée en raison d’un type MIME incorrect (X-Content-Type-Options: nosniff).[En savoir plus] (source inconnue)
      Échec du chargement pour l’élément <script> dont la source est « https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js%3E%3C/script%3E%20%20%20%3C/body%3E%3C/html%3E%3C/div%3E%3C/div%3E%3C/div%3E%3Cdiv%20class=col%20style=width:200px;margin-top:40px;%3E%3Cdiv%20class=component%20style=width:200px;%3E%3Cdiv%20class= ». musique.html:61
      Échec du chargement pour l’élément <script> dont la source est « http://bloggerblogwidgets.googlecode.com/files/way2blogging.org-tripleflap.js ». musique.html:110
      Échec du chargement pour l’élément <script> dont la source est « https://www.googletagmanager.com/gtm.js?id=GTM-M6LN33F ». musique.html:1
      SyntaxError: expected expression, got '&' musique.html:113:21
      ReferenceError: $ is not defined musique.html:136:1
      L’utilisation de « getPreventDefault() » est obsolète. Utiliser « defaultPrevented » à la place. bundle-7746.d7e91303ef.js:39431:134
      Content Security Policy: La source « 'unsafe-inline' » présente dans script-src a été ignorée : « strict-dynamic » a été spécifié (source inconnue)
      Content Security Policy: La source « https: » présente dans script-src a été ignorée : « strict-dynamic » a été spécifié (source inconnue)
      Content Security Policy: La source « http: » présente dans script-src a été ignorée : « strict-dynamic » a été spécifié (source inconnue)
      TypeError: parentDocShell.getDocShellEnumerator is not a function[En savoir plus]
      0