...

View Full Version : javascript document.write problem



tpeck
08-06-2008, 11:07 AM
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



<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:



<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>

binaryWeapon
08-06-2008, 08:37 PM
There are plenty of tools that do the same thing:

http://www.google.com/search?complete=1&hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=html+to+javascript+converter&spell=1

tpeck
08-07-2008, 02:54 AM
Thanks for the list of tools - great!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum