add an option on a web page to be able to turn music on or off

I

islandjohnny

I saw a web site that with a click of the mouse on a graphic, it either
turned on background music, or turned it off. I was wondering if Frontpage
2003 offered that feature and if do, how?
 
T

Trevor Lawrence

islandjohnny said:
I saw a web site that with a click of the mouse on a graphic, it either
turned on background music, or turned it off. I was wondering if Frontpage
2003 offered that feature and if do, how?

FrontPage itself does not, but here is some simple code to do it

Insert this code, using Code or HTML view, where you want the button:
<span id="sound"></span>
<input type="button" value="Play/Stop
Music"
onclick="playSound('audio/minuet.mid')"/>

Insert this JavaScript, using Code or HTML view, between <head> and
</head>:
<script type="text/javascript">
function playSound(fname)
{
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '<embed src="' + fname + '" loop=false
autostart=true hidden>' : ''
}
</script>

The function will play or stop the music on alternate clicks.

Notes:
1. Change the name of the file in "playSound('audio/minuet.mid')" to your
file
2. Some of the quotes are single and some are double. Just cut and paste the
code above to get it right.
 
T

Tim Downie

islandjohnny said:
I saw a web site that with a click of the mouse on a graphic, it
either turned on background music, or turned it off. I was wondering
if Frontpage 2003 offered that feature and if do, how?

How about doing everyone a favour and *resisting* the temptation to have
background music? ;-)

Easily the most irritating feature a web site can have.

Tim
 
B

bgh

Hi, Thanks so much for this help. When I use your code, it gives me a
runtime error of: Line 38 Unterminated String Constant

Here is my actual code and I put (line 38) out to the right in parentheses.
Do you see the mistake I've made? I don't. Your help is so appreciated!!



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Database Interface</title>
<bgsound src="Music/Alone.wma" loop="-1">
</head>

<body bgcolor="#ffffff">

<p><b><font size="+3" color="#000080">Database Interface</font></b></p>
<p><a href="Sample_interface/Customers/results_page.asp"
target="_top">Results Page</a><br />
A page that extracts its content from your database.</p>
<p>
<a href="Sample_interface/Customers/editor/submission_form.asp"
target="_top">Submission
Form</a><br />
A form that will insert its results into your database.</p>
<p>
<a href="Sample_interface/Customers/editor/database_editor.asp"
target="_top">Database
Editor</a><br />
A set of web pages that allow you to view, add, delete and update records in
your
database using a web browser.</p>

</body>

</html>

<span id="sound"></span>
<input type="button" value="Play/Sto
Music"
onclick="playSound('Alone.wma')">

<head><script type="text/javascript">
function playSound(fname)
{
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML ) ? '<embed src="' + fname + '" loop=false
autostart=true hidden>' : '' (line 38)
}
</script>
</head>
 
T

Trevor Lawrence

Well, the code after </html> belongs partly in the <head> section and partly
in the <body> section

Re error in line 38.
This line is split when posted, but I think you had
fname + '" loop=false
when you should have had
fname + "' loop=false

This is very difficult to pick up. The first line reads, between + and loop:
single quote then double quote
which is incorrect

The corrected line reads:
double quote then single quote.

Try this (by cutting and pasting the code)


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta http-equiv="Content-Language" content="en-us" />
<title>Database Interface</title>

<script type="text/javascript">
function playSound(fname)
{
var x = document.getElementById("sound")
x.innerHTML = (!x.innerHTML )
? '<embed src="' + fname + '"'
/* "' is double then single^ ^ '"' is single then double
then single */
+ ' loop=false autostart=true hidden>'
: ''
/* ^ '' is two singles */
}
</script>
</head>

<body bgcolor="#ffffff">
<span id="sound"></span>
<input type="button" value="Play/Stop Music"
onclick="playSound('Alone.wma')">

<!-- Rest of html code -->

</body>
</html>

This worked for me, using a file named 'minuet.mid'. Yours is a .wma file,
but if the player recognises it, it should play OK
 

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

Top