View Full Version : Video Player in Switch Content Script II

03-15-2008, 04:15 PM
1) Script Title: Switch Content Script II

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/switchcontent2.htm

3) Describe problem: I want to use your script to display a small collection of videos on my web site. Putting the players in a <div>'s was simple but I have one nagging problem. If a viewer starts playing a video and then selects a different Tab. The old one closes and the new one opens fine but the video from the now closed tab continues to play and the audio can still be heard.

The player has a javascript API and comes with a FUNCTION to stop a video playing.

I've poked around in both switchicon.js and switchcontent.js and tried to add the function but I'm just not smart enough to figure out where to place the code.

If someone here knows how to do what I want could you please tell me where to put both the function itself and the call that fires it. Here is the function:

<script type="text/javascript">
function sendEvent(swf,typ,prm) {
function getUpdate(typ,pr1,pr2,swf) {};
function thisMovie(swf) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[swf];
} else {
return document[swf];

And this is how they say it should be called:


The sad truth is I don't know where to put either piece of code.

Thanks - Videoguy

03-16-2008, 04:02 AM
Hmmm please clarify which script you're referencing, as you linked to "Tab Content script", yet talked about switchcontent.js, which is for another script...

03-16-2008, 02:36 PM
Thanks for pointing out my error. The script I am actually trying to modify and use is switch content 2

03-17-2008, 12:02 AM
Sure, the logic is to call:


each time a content is closed, with some way to specify the ID of the player (I presume the code in red above) that's associated with different headers. With that in mind, firstly, inside your containers used as the icon togglers, specify a title attribute pointing to the ID of the video player its sub content is carrying, for example:

<div class="eg-bar"><span id="faq1-title" title="video1" class="iconspan"><img src="minus.gif" /></span>What is JavaScript?</div>
<div id="faq1" class="icongroup1">
JavaScript is a scripting language originally developed by Netscape to add interactivity and power to web documents. It is purely client side, and runs completely on the client's browser and computer.
<br />

<div class="eg-bar""><span id="faq2-title" title="video2" class="iconspan"><img src="minus.gif" /></span>Difference between Java & JavaScript?</div>
<div id="faq2" class="icongroup1">
Java is completely different from JavaScript- the former is a compiled language while the later is a scripting language.
<br />

So closing the first header should also call your custom function to stop the player with ID="video1". To do this, inside statusicon.js, make the changes in red below:

var innercontent=document.getElementById(header.id.replace("-title", "")) //Reference content for this header

This only works provided that calling something like:


will in fact stop the player that's reference-able through the name "video1"

03-17-2008, 02:23 PM

I really appreciate your help on this. I am much closer but the call sendEvent(header.title,'stop') is not working for me. In looking at the code within switchicon.js it's obvious the coding style there differs from that used in the functions I have been provided with the player I am using. Could that be the issue.

If I comment out the sendEvent(header.title,'stop') the script works as before but when I don't then clicking on the open/close icons doesn't work. In fact the first appears closed and the second and third are open and I can see the players and in fact control them.

Anything else you might suggest? Once again Thank You

03-17-2008, 11:44 PM
It seems to me from the above that the problem is with sendEvent("someplayer",'stop'). Have you verified that it works in stopping a player when called on its own (ie: a fresh page without Switch Content script added)? If so, what's the relationship between the string "someplayer" and it being used to identify the player? For example, would "someplayer" be the ID attribute of the player?

03-18-2008, 12:08 AM
Yes, the SOMEPLAYER is the javascriptid of the player. I am using 3 .js files to create and display the 3 players. All are identical save the javascriptid's. Here is that code in the hope you may see a conflict that I can correct.

{var so = new SWFObject('jbt.swf','player1','444','353','8');

BTW, on other pages I have on my web site I use the functions and the call and they work as intended. It is only since attempting to use your great script that I've had an issue with this approach.

03-18-2008, 11:35 AM
Do you have URLs to two pages:

1) One with Switch Content and the player script together that doesn't work
2) One with just the player on it and does work (clicking on a link for example stops the player from playing).