Walk thru form, hide all flash object

Hi, I need a bit of JS code that's super-cross-browser compatible (FFox, Safari, Windows IE 6 or better) to walk through a page and for every Flash movie it finds (<embed> or <object> tag, really, I think), it needs to change the display=none or display=block. (I'm loading a CSS layer on top of them, and Flash movies REALLY hate having something load on top of them, so I think the best thing to do is just hide the Flash movies temporarily while I load the top content. It ain't glamorous but it should work...)

I've tried to bang this out myself but can't even figure out how to get JS to give me a list of all embeds/objects on the page, let alone do something with 'em ;-)
pnoericAsked:
Who is Participating?
 
DireOrbAntConnect With a Mentor Commented:
<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function ChangeVisibilityForClass(ClassToHide, Visibility) {
  var ToHide = document.getElementsByTagName('DIV');
    for(var i=0; i < ToHide.length; i++){
              if (ToHide[i].className && ToHide[i].className == ClassToHide) ToHide[i].style.visibility = Visibility;
    }
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript:ChangeVisibilityForClass('FlashDiv', 'hidden')">Hide All Flash Movies</A><BR>
<A HREF="javascript:ChangeVisibilityForClass('FlashDiv', 'visible')">Show All Flash Movies</A>
<P>
<DIV CLASS="FlashDiv">My Flash Movie 1 in here</DIV>
<DIV CLASS="Whatever">Keep this one</DIV>
<DIV CLASS="FlashDiv">My Flash Movie 2 in here</DIV>
</BODY>
</HTML>
0
 
mreuringCommented:
Hmmm, how about just setting a class on the body and write some simple CSS selectors to match your flash? The same class on the body can be used to trigger the element that you're about to show on top of them. Everything could be contained in a function as simple as:

function flipFlopClass (element, class) {
   var ffRE = new RegExp(" ?\\b" + class + "\\b");
   if (ffRE.test(element.className)) element.className = element.className.replace(ffRE, ""); //Remove the class if it's already in
   else element.className += " " + class; //Add the class if it's not already set
}

And your css could be as simple as:

body.overlay object, body.overlay embed {
visibility: hidden;
}

body.overlay div.myoverlay {
display: block;
}

Hope this helps,

 Martin
0
 
pnoericAuthor Commented:
Martin, love where you're going with your solution, but not completely sure how to use it ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.