/    Sign up×
Community /Pin to ProfileBookmark

Referencing a function in another page of a frameset.

I have a frameset with a header and a main frame. The main frame’s page’s body onload event launches an embedded sound file with buttons on that page to start and stop the sound. What I’m looking for is a way to stop the sound when the header frame’s page is clicked.

The script in the main page is:

[code]
<body onLoad=”playSound()”>
<BGSOUND id=”BGSOUND_ID” LOOP=1 SRC=”jsilence.mid”>
<EMBED NAME=”coe” SRC=”coe_start.mp3″
LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>
<script language=”JavaScript”>
<!–
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=’coe_start.mp3′;
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes[‘audio/x-midi’]
&& self.document.coe.IsReady()
)
{
self.document.coe.play()
}
}

function stopSound() {
if (ie4) document.all[‘BGSOUND_ID’].src=’jsilence.mid’;
if ((ns4||ns3)
&& navigator.javaEnabled()
&& navigator.mimeTypes[‘audio/x-midi’]
)
{
self.document.coe.stop()
}
}

The following script is what I’ve tried in the header page, but it doesn’t work.
<head>
<script type=”text/javascript”><!–
function stopSound(){
main.document.coe.stop();
}
if(document.getElementsByTagName) onload = function(){
document.getElementsByTagName(“BODY”)[0].onclick = stopSound;
}
</script>
</head>
[/code]

Any suggestions will be greatly appreciated.
Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@rootJun 23.2007 — Audio playback should not be imposed on the site visitor but be an option that they can select to start the playback...

Audio is frowned upon like altering a browsers window size or popups... these are the top annoyances you will come across on the internet.
Copy linkTweet thisAlerts:
@RobDavidJun 25.2007 — I agree, audio is a bad idea.

But since your question was more javascript related, who are we to judge what you do with it.

I'm not sure what coe is...but you could reference a main page script in a frameset from another frame using top.[I]framename[/I].stop()
×

Success!

Help @jmclaughlin_hig 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.19,
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,
)...