Dmitry Baranovskiy’s Blog α




Flash updater for Internet Explorer

12 January 2007

Internet Explorer recently introduced a new security feature” into their browser that have had a negative impact on Macromedia Flash objects. The feature blocks Flash interactivity by default instructing the user to click” on the flash movie to manually activate it. I am sure you will agree with me that this is really annoying! Soon after releasing this feature Microsoft, and then Adobe (together with everyone else who had a half decent knowledge of JavaScript) published scripts to rectify this issue. However they all have negative aspects for those of us who care about web standards such as:

  • You need to put the inline script element in your body element
  • You should have a noscript tag to make the flash movie available if JavaScript is turned off
  • The scripts use the ugly document.write method

So when I recently faced this issue I wasn’t impressed with the existing solutions at all. I decided to write something better and came up with this simple script. It is a clean DOM script and it doesn’t require any big changes in your HTML code. Just add a unique class name to your flash object (flash-movie” in my case) and the JavaScript will find and replace it with an object tag that works and Internet Explorer will no longer block it. If JavaScript is turned off through the browser the existing flash object tag will remain the same.

However, bear in mind that I designed this script for a particular site where flash movies are quite simple in terms of communication with JavaScript or each other. This script will make the Flash movies start twice, which may cause some problems for complex flash applications with multiple objects communicating with each other.

function doFlash()
{
    var objects = document.getElementsByTagName("object");
    for (var i = 0; i < objects.length; i++) {
        if (/(^|\s)flash-movie($|\s)/.test(objects[i].className)) {
            var width = objects[i].getAttribute("width") || 400;
            var height = objects[i].getAttribute("height") || 300;
            var params = objects[i].getElementsByTagName("param");
            var movie = null;
            for (var j = 0, jj = params.length; j < jj; j++) {
                if (params[j].getAttribute("name") == "movie"
&& params[j].parentNode == objects[i]) {
                    movie = params[j].getAttribute("value");
                }
            }
            if (movie) {
                var f = document.createElement("embed");
                f.setAttribute("type", "application/x-shockwave-flash");
                f.setAttribute("src", movie);
                f.setAttribute("width", width);
                f.setAttribute("height", height);
                f.setAttribute("quality", "high");
                f.setAttribute("pluginspage",
                "http://www.macromedia.com/go/getflashplayer");
                objects[i].parentNode.replaceChild(f, objects[i--]);
            }
        }
    }
}
if (window.attachEvent) {
    window.attachEvent("onload", doFlash);
}

, , ,

25 Jan 07 1:20pm

R Walker

This is very similar to http://therippa.blogspot.com/2006/03/activateactivex.html which was created almost a year ago. You must be lucky enough to not have used Flash for a long time?