1

I'm trying to write a javascript function that detects embedded objects. As the result of my 3 hour research i found that there are 2 major approach to use a .swf file in html

  1. Object tag, example: <object data="intro.swf" height="200" width="200"/>

  2. Embed tag, example:<embed src="intro.swf" height="200" width="200"/>

But there is a third approach which is cross-browser and somehow more common:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"
    width="100"
    height="100">
<param name="movie" value="sample.swf">
<param name="quality" value="high">
<embed src="sample.swf" quality="high" width="100" height="100"
       type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">

I found a function here:

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    {
        return document.getElementById(movieName);
    }
}

but this function takes the id/Name Attribute as argument,and is not good for me. I thought that it's better to detect browser first and then look for flash object. I'm still trying. What should I do to detect RENDERED flash object??

1
  • I once wrote a bookmarklet to find flash, and I remember this fun fact: objects can be nested, so there may be an object decendant of an object. And of course, embeds are commonly used as children of objects. You need to filter that one out. Commented Feb 19, 2012 at 8:18

1 Answer 1

1

How about this:

jQuery:

$('object:has(embed)');

Vanilla JS:

function getCompleteObjects () {
    var objects = document.getElementsByTagName('object'),
        len = objects.length,
        complete = [],
        i = 0;

    for (; i < len; i++) {
        var embed = objects[i].getElementsByTagName('embed');
        if (embed) {
            complete.push(objects[i]);
        }
    }

    return complete;
}

jQuery fiddle: http://jsfiddle.net/Kai/9vFgT/

Vanilla JS fiddle: http://jsfiddle.net/Kai/WZEvF/

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for your answer pal, I knew about document.embeds , but what about object tags? It not important for me to know that if the flash has been successfully loaded. I only need to have whole flash objects.
In IE the object tag works and embed tag is ignored. but (as I think, I'm not sure) none-IE browsers use embed tag, if embed tag is included in object tag (like the third way I mentioned in question).
I exactly need the flash object, not object/embed tags of a page.
The Flash object's API is exposed via the DOM object, so practically there's no difference between HTML element and Flash object.
There's no way to tell if a Flash object is loaded unless it provides an API (callback or property) for that (example). If you know there's some API method you may test for their existence in the DOM element like so: if ($('#someflash').getPlaylistIndex).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.