Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts

    javascript document.write problem

    Hi. Occasionally I need to produce javascript code within an HTML page which inorporates the document.write technique.

    Rather than work it out, I usually go to: http://www.stevenolte.com/docwriter.html

    Steve's code generator starts me off in the right direction and I take it from there. But for some reason, the generator no longer functions correctly (at all? - does anyone know of an alternative?)

    So I am stuck. Here is a bunch of stuff I have tried to "document.write" but it doesn't work.

    Can anyone tell me the bit that I haven't unescaped? Or whatever the problem is? (I don't think it really matters what the original does.)

    The original code is below it.

    Thanks,

    Terry

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    document.write("<script language='JavaScript'>");
    document.write("<embed src='file:///C:/404SGAM/bach/end.mp3' LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND></embed>");
    document.write("<!--"); 
    document.write("ver=parseInt(navigator.appVersion)");
    document.write("ie4=(ver>3  && navigator.appName!='Netscape')?1:0");
    document.write("ie4=(ver>3  && navigator.appName!='Netscape')?1:0");
    document.write("ns4=(ver>3  && navigator.appName=='Netscape')?1:0");
    document.write("ns3=(ver==3 && navigator.appName=='Netscape')?1:0");
    document.write("function playSound() {");
    document.write("if (ie4) document.all['BGSOUND_ID'].src='file:///C:/404SGAM/bach/end.mp3';");
    document.write("if ((ns4||ns3)");
    document.write("&& navigator.javaEnabled()");
    document.write("&& navigator.mimeTypes['audio\/x-midi']");
    document.write("&& self.document.Bach.IsReady())");
    document.write("{self.document.Bach.play()}}");
    document.write("function stopSound() {");
    document.write("if (ie4) document.all['BGSOUND_ID'].src='';");
    document.write("if ((ns4||ns3)");
    document.write("&& navigator.javaEnabled()");
    document.write("&& navigator.mimeTypes['audio\/x-midi'])");
    document.write("{self.document.Bach.stop()}}");
    document.write("//-->");
    document.write("<\/script>");
    </SCRIPT>
    (the unescaped bits are in red)

    Original Code:

    Code:
    <script language="JavaScript">
    document.write("<embed src='file:///C:/404SGAM/bach/end.mp3' LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND></embed>");
    <!--
    ver=parseInt(navigator.appVersion)
    ie4=(ver>3  && navigator.appName!="Netscape")?1:0
    ns4=(ver>3  && navigator.appName=="Netscape")?1:0
    ns3=(ver==3 && navigator.appName=="Netscape")?1:0
    
    function playSound() {
    if (ie4) document.all['BGSOUND_ID'].src='file:///C:/404SGAM/bach/end.mp3';
     if ((ns4||ns3)
      && navigator.javaEnabled()
      && navigator.mimeTypes['audio/x-midi']
      && self.document.Bach.IsReady()
     )
     {
      self.document.Bach.play()
     }
    }
    
    function stopSound() {
     if (ie4) document.all['BGSOUND_ID'].src='';
     if ((ns4||ns3)
      && navigator.javaEnabled()
      && navigator.mimeTypes['audio/x-midi']
     )
     {
      self.document.Bach.stop()
     }
    }
    //-->
    </script>
    Last edited by tpeck; 08-06-2008 at 11:11 AM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    There are plenty of tools that do the same thing:

    http://www.google.com/search?complet...verter&spell=1

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    882
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Thanks for the list of tools - great!
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •