/    Sign up×
Community /Pin to ProfileBookmark

Sound Off script

[SIZE=1]I desperately need a Sound Off Button (and the script, of course to make it work) for my site. A lot of my visitors really, really like the music. Others have told me that I need to have a sound off button for those who don’t care to listen.[/SIZE] [COLOR=darkblue]anyone help?…..PLEASE????[/COLOR] [COLOR=darkblue]This is my first time here, so forgive me if I don’t follow format exactly. I’ll learn![/COLOR] ?

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@ExuroJun 29.2004 — It would help to know what method you're using to play the music...
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJun 29.2004 — I'm using a midi file. Is that what you want. It's just in there as background music=
Copy linkTweet thisAlerts:
@TheTeenScripterJun 29.2004 — I think he means are you using <embed> or <bgsound> ?? .. if you're using bgsound, make your script like this...

<body>

<bgsound src="file.midi" loop=1 hidden=true ID="bgsound">

<script language="javascript"> bgmusic = document.all.bgsound.src; function soundCtrl(onoff) { if(onoff == "off") { document.all.bgsound.src=''; } else if(onoff == "on") { document.all.bgsound.src=bgmusic; } } </script>

<a href="#" Style="color:blue;" onclick="soundCtrl('off')">Stop Music</a> <a href="#" Style="color:blue;" onclick="soundCtrl('on')">Restart/Play Music</a>

</body>

You can change this script to make images instead of text. Just change the text inside the <a></a> tags with <img src="image.jpg" border="0"> tags.
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJun 29.2004 — [SIZE=3]Thanks so much! I'll try it this afternoon![/SIZE] ?
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJun 30.2004 — sorry,your code did not work....

the music is bg music, not an embed. I know your code was supposed to do that, but it did not work. thanks anyhow.
Copy linkTweet thisAlerts:
@ExuroJun 30.2004 — It worked for me... Here's pretty much the same script re-written with a toggle button and it uses [FONT=courier new]getElementById()[/FONT] rather than [FONT=courier new]document.all[/FONT]. Keep in mind that <bgsound> only works on Internet Explorer.

[size=2]
&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
var soundPlaying = true;
var soundFile = "";
function getSrc() {
soundFile = document.getElementById('bgMusic').src;
}
function toggleSound() {
if (soundPlaying) {
document.getElementById('bgMusic').src = "";
}
else {
document.getElementById('bgMusic').src = soundFile;
}
soundPlaying = !soundPlaying;
}
//--&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="getSrc();"&gt;
&lt;input type="button" value="Toggle Music" onclick="toggleSound();" /&gt;
&lt;bgsound id="bgMusic" src="file.mid" loop="-1" /&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
[/size]
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJun 30.2004 — [COLOR=darkblue]Thanks, I'll give it a try......really, really new to JavaScript, but I'm working on it. I've only been doing html for a couple of months, so please be patient with me. I already have 4 pages up and I didn't use pagebuilder or any of those. I did it all myself in Notepad, so I think I'm doing okay. Thank you for your patience![/COLOR]
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJun 30.2004 — Okay, sorry, but I can't get this one to turn off the music, either. The toggle button shows up. I'm pretty sure I pasted the .mid file in the right place, but it won't work.....doesn't stop the music. [COLOR=royalblue]I really don't want to take the music out altogether, because there are some folks who really like it - AND I LIKE IT! [/COLOR] :mad:
Copy linkTweet thisAlerts:
@ExuroJul 01.2004 — Both scripts work for me, so I don't know what the deal is... My suggestion is to use an embed, and then you can let the user hit the play button of whatever if they want it to play...
Copy linkTweet thisAlerts:
@Lit_l_BitsauthorJul 01.2004 — [COLOR=teal]Thanks for your help. I did change from bgmusic to embed and used a different switch to pause/play. It's working fine now. [/COLOR] [COLOR=teal]As I said originally, I'm new, new, new to all of this. The more I learn to do, of course, the more confident I become. If it's bothersome to forum members, I will refrain from asking questions here.[/COLOR] ?
×

Success!

Help @Lit_l_Bits spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...