Embedding silverlight using <EMBED> tag

UPDATE (thanks Ian G):

My tests were conducted with IE7/Firefox 3b5 and RC1. Unfortunatelly, I did not know about the fact that the beta/rc versions of Firefox 3 as well as Silverlight 2b1 seem to suffer from a few deadly bugs:

http://tempvariable.blogspot.com/2008/04/silverlight-and-firefox-3.html
https://bugzilla.mozilla.org/show_bug.cgi?id=424013
http://blog.sublimeintervention.com/userscripts/slff3unfuck.user.js

After running several tests on Seamonkey 1.1.9, IE7 & Firefox 3 RC2 all I can say is that both Seamonkey (and, I assume, 2.x versions of Firefox as well as IE7 can properly render Silverlight apps using the embed tag and data="data:application/x-silverlight," attribute. Firefox 3 RC2 simply crashes.

Well, Firefox 3rc2 also crashes if I try to......you know......browse web pages on the Internet :p, sneeze or simply try to start it.

<embed
data="data:application/x-silverlight,"
type="application/x-silverlight-2-b1"
src="uri_to_your_sl_control"
width="500" height="500"
source="uri_to_your_sl_control"
onerror="javascript:alert('error');"
background="white"/>



You can safely ignore the rest of the post.....


ORIGINAL Post below

For reasons not worth mentioning here, I had to embed a silverlight control without the use of javascript, iframes and/or the <object> tag. Since you're here, I assume that you already know that there's virtually null, nill, none, zero, 0 documentation out there about how silverlight can be used with the <embed> tag.

Frankly, I can't even say that I know the difference between <object> and <embed>. For all I care, it's just politics but, as I found out, they do seem to work in slightly different ways.

In case you wonder, here's the MSDN official way of instantiating a silverlight plugin: http://msdn.microsoft.com/en-us/library/cc189089(VS.95).aspx Yup, it seems a bit outdated but that's a different story.

What I needed was a way to instantiate the control using the <embed> tag. Without further delay, here's the working result:

<embed id="slp" data="data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAAAYLgAAQ1gAAAwAAAB3AGgAaQB0AGUAAAAAAAAAAAAAAHwAAABoAHQAdABwADoALwAvAHAAYQB5AHUAcAAuAHUAYgBpAHEAdQBpAHQAeQAuAHIAbwAvAEMAbABpAGUAbgB0AEIAaQBuAC8AYwBvAG0ALgBiAGsAZABjAC4AdwBpAGQAZwBlAHQAcwAuAGEAZABkAGU"
type="application/x-silverlight-2-b1"
src="[uri to your silverlight control]"
width="400" height="120"
source="[uri to your silverlight control]"
onerror="javascript:alert('error');"
background="white">



As you can see, it's a fairly standard 'translation' that mapped all the object params to attributes. The only difference is in the data attribute. Microsoft says that the data attribute "Streamlines the instantiation process. The data attribute is required, and it is recommended that the value be the Silverlight application MIME type - data:application/silverlight."

I tried setting the value to "application/silverlight," as recommended but without any success; the control simply didn't show up. Using IE Developer Toolbar I discovered that the actual value for data is "data:application/x-oleobject;base64,QfXq3+HzJEysrJnDBxUISgAIAABXKQAAAh8AAAwAAAB3AGgAaQB0AGUAAAAAAAAAAAAAAE4AAAAvAEMAbABpAGUAbgB0AEIAaQBuAC8ARgBsAGEAdwBsAGUAcwBzAEMAbwBkAGUAUgBlAGcAZQB4AFQAZQBzAHQAZQByAC4AeABhAHAAAAAYAAAAAAAAABYAAABfAF8AcwBsAEUAcgByAG8AcgAwAAA"
Not sure what it is, what it does or how it got there but it works. Enjoy!

Comments

Unknown said…
That data string you've supplied might not work for everyone unfortunately...

It includes a base64 encoded blob that contains various bits of data, including the path to your XAP. If you run the base64 part through a decoder, you'll see that amongst other things, it includes the text "/ClientBin/FlawlessCodeRegexTester.xap".

You said you tried "application/silverlight," but that's not actually quite what's recommended. Did you try:

data="data:application/silverlight,"

Note the data: at the start (it's not just the name of the attribute).

Not sure if that'll make any difference though - I don't think the embed tag is officially supported for silverlight...
bkdc said…
Ian, thanks for your great observations - I should have paid more attention to it in the first place but your comments did clear things up.

Popular Posts