« SilverLight Panel | Main | SilverLight 1.0 RC1 ready... »

Including SilverLight.js

One the the things you will quickly notice if your using the SilverLight Visual Studio template or for that matter follow any of the QuickStarts  is each SilverLight project you create ends up with a copy of  the SilverLight.js being added.

This contains the logic to detect if SilverLight is installed, show the install icon, and if installed allow you to create content.  Then basically on each page that uses SilverLight - you need to include this JavaScript file as such...

<script type="text/javascript" src="Silverlight.js"></script>

I really don't like the idea of having a bunch of copies of this all scattered across my apps that use SilverLight.  I would rather have one place that it's sucked in from and used on the page - that way when it's updated - you know like with 1.0 RTM is released, I don't have to hunt all around to find it.

I'm still not sure what I want, but  know I want it to be easy...So my first thought is something similar to ASP.NET AJAX ScriptManager - I just want to drop something on my page and have it be SilverLight Enabled.

<cc1:CTCSilverLightMgr ID="CTCSilverLightMgr1" runat="server" />

This control could then take care of including the script ( more on that in a minute) and any other options I want to add as properties later.

I then started thinking about how to include the SilverLight.js.  My first attempt gave me a painful reminder of why it had to be a separate file.  If you recall that little security / patent fix that happened where all embedded content had to be clicked to activate - well guess what that applies to SilverLight as well.  Deep inside the SilverLight.js it's creating embed or plugin type logic similar to how you would enable Flash on a page.  If you were to slipstream the SilverLight.js into the page itself, your SilverLight renders but guess what - it has the nice Click Here To Activate on it.  So the bottom line is you must include the contents of SilverLight.js somehow to get around that.

My second thought was via a handler, and that's what seems to be working best.  I have embedded one copy of it inside my Common SilverLight Class Library and included a 3-5 line HttpHandler that will spit it out when requested by the my CTCSilverLightMgr control.  This way, using it with an ASP.NET project is as simple as adding one line to the HttpHandler section of the web.config

Posted on Sunday, July 29, 2007 at 09:11PM by Registered CommenterDavid Yack | CommentsPost a Comment

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>