Text to Speech Javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • windsorben
    New Member
    • Nov 2006
    • 23

    Text to Speech Javascript

    Why do my images dissappear after I clik on them? Otherwise, the text to speech is working just fine. However, it is not functional if the images dissappear.

    [HTML]<script language="JavaS cript" type="text/javascript" >
    <!--

    function insertTTS(tts,l oop) {
    document.write( '<object classid="clsid: 166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macrom edia.com/pub/shockwave/cabs/director/sw.cab#version= 8,5,0,0" ID=ib_tts width=1 height=1>\n');
    document.write( '<param name=src value="media/tts.dcr">\n');
    document.write( '<param name=swRemote value="swSaveEn abled=\'true\' swVolume=\'true \' swRestart=\'tru e\' swPausePlay=\'t rue\' swFastForward=\ 'true\' swContextMenu=\ 'true\' ">\n');
    document.write( '<param name=swStretchS tyle value=none>\n') ;
    document.write( '<param name="sw9" value="'+tts+'" >\n');
    document.write( '<param name="sw8" value="'+loop+' ">\n');
    document.write( '<embed src="media/tts.dcr" bgColor=#FFFFFF width=1 height=1 swRemote="swSav eEnabled=\'true \' swVolume=\'true \' swRestart=\'tru e\' swPausePlay=\'t rue\' swFastForward=\ 'true\' swContextMenu=\ 'true\' " swStretchStyle= none type="applicati on/x-director" pluginspage="ht tp://www.macromedia. com/shockwave/download/" sw9="'+tts+'" sw8="'+loop+'"> </embed>\n');
    document.write( '</object>\n');
    }
    //-->
    </script>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>

    </head>
    <p><img src="dog.jpg" width="50" height="66" onclick="insert TTS('My favorite animals', 'false')" /></p>
    <p><img src="dog.jpg" width="50" height="66" onclick="insert TTS('My favorite martian', 'false')" /></p>

    <p>&nbsp;</p>
    </body>
    </html>[/HTML]
    Last edited by acoder; Nov 20 '07, 10:28 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can't use document.write after the page has loaded.

    Either create the objects and append them to the body or set the innerHTML property of a div element within the page.

    Comment

    • windsorben
      New Member
      • Nov 2006
      • 23

      #3
      What would the div element look like? Sorry, I'm a beginner.


      Originally posted by acoder
      You can't use document.write after the page has loaded.

      Either create the objects and append them to the body or set the innerHTML property of a div element within the page.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by windsorben
        What would the div element look like? Sorry, I'm a beginner.
        It doesn't necessarily have to be a div. You could even use the <p> tag that you already have.

        Give the element an id:
        [HTML]<div id="content"></div>[/HTML]

        In your function, access the element:
        [CODE=javascript]var div = document.getEle mentById("conte nt");[/CODE]Also convert the document.write statements into a string and then set div.innerHTML to that string.

        One final thing: you have an opening body tag missing.

        Comment

        • windsorben
          New Member
          • Nov 2006
          • 23

          #5
          Would you mind showing me how this would look in my code. I hate to take up your time but what I've tried isn't working.
          Thanks!

          Originally posted by acoder
          It doesn't necessarily have to be a div. You could even use the <p> tag that you already have.

          Give the element an id:
          [HTML]<div id="content"></div>[/HTML]

          In your function, access the element:
          [CODE=javascript]var div = document.getEle mentById("conte nt");[/CODE]Also convert the document.write statements into a string and then set div.innerHTML to that string.

          One final thing: you have an opening body tag missing.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            To get you started:
            [code=javascript]function insertTTS(tts,l oop) {
            var str = '<object classid="clsid: 166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macrom edia.com/pub/shockwave/cabs/director/sw.cab#version= 8,5,0,0" ID=ib_tts width=1 height=1>';
            str += '<param name=src value="media/tts.dcr">';
            str += '<param name=swRemote value="swSaveEn abled=\'true\' swVolume=\'true \' swRestart=\'tru e\' swPausePlay=\'t rue\' swFastForward=\ 'true\' swContextMenu=\ 'true\' ">';
            // and likewise for the rest of the document.write statements.
            document.getEle mentById("conte nt").innerHTM L = str;
            }[/code]
            If you can't get it to work, post your code.

            Comment

            • windsorben
              New Member
              • Nov 2006
              • 23

              #7
              thanks for your help!

              Thank you for helping a beginner!
              Last edited by windsorben; Nov 21 '07, 07:46 PM. Reason: caught my mistake

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                No problem, glad you got it working.

                Comment

                Working...