Solved

Walk thru form, hide all flash object

Posted on 2006-07-11
3
1,834 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

867 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

18 Experts available now in Live!

Get 1:1 Help Now