Article
Flash Player Detection Techniques Unearthed
When should this detection method be employed?
This method currently has the best chance of getting the exact version information for nearly all visitors to a page. As such, it's most useful when you're dealing with an anonymous audience:
- Pages for the general browsing public.
- Intranet sites when Flash Player version is not known.
- When you want to show alternate content based on what the script finds.
When should this detection method be avoided?
- If the site visitor does not have scripting enabled on their machine, this method will fail. Your decision to check whether scripting is enabled should be based on the knowledge that approximately 98% of users will have client side scripting running. Employ <noscript> tags to get around this and supply alternate content in those cases.
- This method will not work in browsers that do not support client side scripting, such as Internet Explorer for the Mac versions 3 and 4. It's time to be forward-compatible in this case, and if required a sniff can be performed for the small population of these browsers.
- When you want your alternate content available for access by screen readers.
- When you don't want to bloat pages or lock your content up in script, which leads us to a few lightweight detection methods.
Cascading XHTML: the Object Tag
The object tag is the w3c recommended element for deploying any object within a markup based setting. “Object" in this sense means any non-text content, such as a Quicktime movie, a Java applet, an image, a Flash movie and so forth.
The recommendation states that if a browser has no way to deploy the content targeted by an Object tag, it should attempt to render the content held within the Object tag. If this is not possible, it should attempt to render the first available content it finds.
This is an elegant and accessible way to handle Flash detection. For instance, the first object tag can link to the required Flash movie, the next nested object tag could attempt to deploy an image. If this were not possible, nested in this tag would be some descriptive text about the movie.
It's a wonderfully simple method, based on the cascading ability of the Object tag. It is the W3C recommended way for user agents to handle objects, and works in all standards-compliant browsers. In respect to Flash detection, it's an extension of the “manyana" method described at the start of this article.
Code example
Below is the same valid XHTML described at the start of the article, with some additions:
<object
data="index.swf"
type="application/x-shockwave-flash"
codebase="http://<?=$_SERVER['HTTP_HOST']?>/sitepoint/flashdetection/testmovie/"
width="550"
height="400">
<param name="movie" value="http://<?=$_SERVER['HTTP_HOST']?>/sitepoint/flashdetection/testmovie/index.swf" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ededed" />
<!-if no Flash Player present, render an image -->
<object
data="alternate.gif"
type="image/gif"
width="550"
height="400">
<!-if images turned off, or a text only browser, render the text -->
<p>Alternate descriptive content can go here, plus a link to the Flash Player download page for the user to optionally activate.
<br />
This text will be rendered if the user-agent cannot render the Flash file or the GIF image.
</p>
</object>
</object>
Alas, elegant as this detection technique is, and even though object is an HTML4 recommendation from 1997, this solution seriously lacks browser support. Internet Explorer for Windows will attempt to render all object tags present in the code, so you will see a Flash movie and a GIF image if the Player is installed.
In XHTML2.0, object will be the method used to deploy images, so we should hopefully expect better browser support for this in the future. For now, though, it is but a coder's dream.
When should this method be employed?
- When you know that your site visitors are using standards-compliant browsers. For example, an Intranet with a Gecko-based browser used as default.
When should this method be avoided?
- When you're dealing with an anonymous audience.
- When your audience uses predominantly Internet Explorer for Windows as a Web browser.
Note that version detection within the markup is unavailable, so if this is important (for instance, if you use Flash Player 6 ActionScript), use inbuilt version detection within Flash: