/    Sign up×
Community /Pin to ProfileBookmark

I have a page with a menu on the left. When you click on one of the menu items, a <div> appears on the page with a movie. However, if you click a different menu item, the movie still plays even though the div is replaced by a different div. Is there a way to stop the movie from playing in the first div once a different menu item is clicked? Here’s the code:

<script> var element_id = “”;
var state = 0;
function open_close ( id ) {
if ( state == 0 ) {
state = 1;
element_id = id;
document.getElementById( id ).style.display = ‘block’;
} else {
if ( id == element_id ) {
// state = 0;
// document.getElementById( id ).style.display = ‘none’;
} else {
state = 1;
document.getElementById( element_id ).style.display = ‘none’;
document.getElementById( id ).style.display = ‘block’;
element_id = id;
}
}
}
</script>

<a href=”#” onClick=”open_close(‘d1’);”></a>
<div id=”d1″ style=”display:none”><embed src=moviefile></embed></div>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERAug 07.2008 — Are you trying to stop the movie display or just hide it?

Depending upon how your menu is set-up,

you could initially hide all elements in the list (every time)

and then reveal only the current selection.

This would have the effect of hiding the movie

when another menu item is selected.
Copy linkTweet thisAlerts:
@IAmAnIdiotAug 08.2008 — Are you trying to stop the movie display or just hide it?

Depending upon how your menu is set-up,

you could initially hide all elements in the list (every time)

and then reveal only the current selection.

This would have the effect of hiding the movie

when another menu item is selected.[/QUOTE]


I've never embedded a video, but here's a question for you... will "hiding it" make the audio stop? And if you are forced to do something such as change the innerHTML, would that be prone to causing errors?
Copy linkTweet thisAlerts:
@JMRKERAug 08.2008 — I've never embedded a video, but here's a question for you... will "hiding it" make the audio stop? [/QUOTE]
Don't know, I have not done it either.

With you current code, does it play the video?

My guess would be that the 'hide' would not stop the video, just cause it to disappear from the screen. Clicking on a 'show' would probably continue from where ever it is unless it is downloaded from the link from the start again.

Have you tried it yet?

Changing the 'innerHTML' usually just changes the display of text.

I have never tried it using anything other than text and images.

You might consider opening the video in a new window.


Then when the user clicks on close, the video/audio should stop.

Perhaps some other forum members know more about this subject.
Copy linkTweet thisAlerts:
@kavicarterauthorAug 08.2008 — Yes, I'm trying to stop the video/audio from playing. As it is set up right now, it "disappears" when another menu item is selected, but you still here it in the background because I'm not sure how to add a stop code to the javascript that activates when another menu item is clicked.
Copy linkTweet thisAlerts:
@IAmAnIdiotAug 10.2008 — Yes, I'm trying to stop the video/audio from playing. As it is set up right now, it "disappears" when another menu item is selected, but you still here it in the background because I'm not sure how to add a stop code to the javascript that activates when another menu item is clicked.[/QUOTE]

The first thing that I would try would be overwriting the innerHTML of that div, and if I felt that was going to cause errors, I would look into the possibility that the player handling the video has some API set that allows javascript to stop the video.
×

Success!

Help @kavicarter 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...