JavaScript syntax - Help

A

ArbolOne

can anyone tell me what is wrong with this syntax?
document.writeln('<bgsound src="' + soundfile +'" loop=1> +
volume=v>');

TIA
 
V

VK

can anyone tell me what is wrong with this syntax?

1) Quotes and 2) resulting HTML tag format?
document.writeln('<bgsound src="' + soundfile +'" loop=1> + volume=v>');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

document.writeln('<bgsound src="'.concat(
soundfile,
'" loop=1',
' volume=',
v,
'>'
));
 
T

Thomas 'PointedEars' Lahn

VK said:
1) Quotes and 2) resulting HTML tag format?

There is no "HTML tag format", idiot.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

document.writeln('<bgsound src="'.concat(
soundfile,
'" loop=1',
' volume=',
v,
'>'
));

Complete utter nonsense to call concat() where a simple proper concatenation
would have sufficed.


PointedEars
 
T

Thomas 'PointedEars' Lahn

ArbolOne said:
can anyone tell me what is wrong with this syntax?
document.writeln('<bgsound src="' + soundfile +'" loop=1> +
volume=v>');

Everything.

1. Use document.write() instead.

2. The `bgsound' element is proprietary, obsolete, and unnecessary.
You must have been getting this from an obsolete or erroneous
tutorial or Web site.

3. Suppose the value of `soundfile' is "foo", this would generate

<bgsound src="foo" loop=1> + volume=v>

Probably you are (not) looking for this:

document.write('<bgsound src="' + soundfile + '" loop=1'
+ 'volume="' + v + '">');

Again, that is recommended against from the HTML point of view. Use instead:

document.write([
'<object data="' + soundfile + '">',
' <param name="FileName" value="' + soundfile + '">',
' <param name="URL" value="' + soundfile + '">',
' <param name="playCount" value="1">',
' <param name="volume" value="' + v + '">',
'<\/object>'
].join("\n"));

The `param' elements should take care of Microsoft Media Player 9+ support,
but you might have to branch with a `clsid' attribute for the `object'
element in order to avoid ActiveX warnings (see
<http://msdn.microsoft.com/en-us/library/aa393200(VS.85).aspx>). The only
alternative I know is the proprietary `embed' element.

That said, avoid using background sounds/music on Web sites as they will
likely annoy users. Notable exceptions include those where the background
sound or music is probably important for user experience, such as the proper
background sound in a simulation or the newest title playing on a music
group's Web site. Be sure to provide a way to shut it all sounds off, though.


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top