• ¿Quieres apoyar a nuestro foro haciendo una donación?, entra aquí.

problema con <Body onLoad=()> ¿Como se llama la funcion?

arekuzu

Pendej@
Registrado
2007/07/14
Mensajes
219
Tengo un script sencillo:
HTML:
  <script  src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script>
     var voices = [];
    $(document).ready(function() {
       voices = window.speechSynthesis.getVoices();
       console.log('Get voices ' + voices.length.toString());
          for(var i = 0; i < voices.length; i++ ) {
            console.log("Voice " + i.toString() + ' ' + voices[i].name);
          }
        $("#demo_1").on('click', function(e) {
          // e.preventDefault();
          var u1 = new SpeechSynthesisUtterance('Has llegado a tu destino');
          u1.lang = 'es-ES';
          u1.pitch = 1;
          u1.rate = 1;
          u1.voice = voices[10];
          u1.voiceURI = 'native';
          u1.volume = 1;
          speechSynthesis.speak(u1);
          console.log("Voice " + u1.voice.name);
        });   
    });
  </script>
</head>
<body>
  <input type="button" id="demo_1" value="Speak">
</body></html>
al hacer clic en el botón funciona perfecto, pero como lo llamo desde la etiqueta <body>, para que hable al cargar la pagina?
 
borra la 2da línea, está puro weiando nomas

:buenaonda:
 
Tengo un script sencillo:
HTML:
  <script  src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script>
     var voices = [];
    $(document).ready(function() {
       voices = window.speechSynthesis.getVoices();
       console.log('Get voices ' + voices.length.toString());
          for(var i = 0; i < voices.length; i++ ) {
            console.log("Voice " + i.toString() + ' ' + voices[i].name);
          }
        $("#demo_1").on('click', function(e) {
          // e.preventDefault();
          var u1 = new SpeechSynthesisUtterance('Has llegado a tu destino');
          u1.lang = 'es-ES';
          u1.pitch = 1;
          u1.rate = 1;
          u1.voice = voices[10];
          u1.voiceURI = 'native';
          u1.volume = 1;
          speechSynthesis.speak(u1);
          console.log("Voice " + u1.voice.name);
        });  
    });
  </script>
</head>
<body>
  <input type="button" id="demo_1" value="Speak">
</body></html>
al hacer clic en el botón funciona perfecto, pero como lo llamo desde la etiqueta <body>, para que hable al cargar la pagina?

Como dice el joven de arriba, borrar la segunda linea, porque estas abriendo el tag <script> por segunda vez, por eso no reconoce el código
:santa:
 
Volver
Arriba