Solved

Walk thru form, hide all flash object

Posted on 2006-07-11
3
1,833 Views
Last Modified: 2012-08-14
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 ;-)
0
Comment
Question by:pnoeric
3 Comments
 
LVL 26

Accepted Solution

by:
DireOrbAnt earned 500 total points
ID: 17087445
<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
 
LVL 17

Expert Comment

by:mreuring
ID: 17089054
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
 

Author Comment

by:pnoeric
ID: 17097183
Martin, love where you're going with your solution, but not completely sure how to use it ;-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now