Windows Media Player Javascript Detect and Embed

Geoff Stearns over at wrote a great script to detect and embed Flash objects, called SWFObject embed. What I love about it is that it is really simple to use and bypasses the problems of the Eolas v Microsoft debarcle (Click to activate this control). He also produced a Quicktime detect and embed alongside the Flash SWFObject that is also very useful. I needed a similar script for Windows Media Players, so without being able to find a great example, I knocked this up, based on his code.

First we create the WMPObject:

Then deal with any parameters that are passed:

We then have a function to generate the core HTML and return a string of HTML code:

And deal with attributes:

Write the generated HTML out to the page:

And deal with plugin detection:

Then to use the WMPObject, you can use the following:

Download a fully functional demo of this code from

Published by

Ben Powell

Ben Powell was born in Wales and after living in several European countries is now resident in Germany. He is a frequent blogger, software developer and a social techie.

7 thoughts on “Windows Media Player Javascript Detect and Embed”

  1. I have created a zip file with the Javascript include file only. There is no demo, but at some point I’ll warp it all together.

    If you follow the instructions for the Quicktime example that Geoff Stearns has created and switch the references in your HTML code for the wmpObject instead, you shouldn’t go far wrong.

    The file can be found here:

    Geoff’s information on the Quicktime Object detect and embed is here:

  2. Excellent work.

    Unfortunately, a huge problem remains: when scaling embedded video, firefox (and other non-IE pc browsers) tend to not scale the video height when user has WMP 11 installed. This doesn’t have anything to do with the script though. The problem relies on the general plugin implementation.

    For example, let’s say you wanted to scale up a 320×240 video to 640×480 – the video width is expanded to 640px but the height remains at 240px.

    Have you guys come around this problem?

  3. Hi Ben,
    Using your isWMPInstalled() when testing on my system it will return two instances of WMP, one for the full WMP and one for the Firefox WMP Plugin which I’ve also installed. You don’t know how to check for just the plugin do you? I’m wanting FF users to see wmp visualization as music plays but this will only work with wmp plugin installed.

Feel free to leave constructive comments that aren't spam!