Porting to MySpace using Silverlight

I was looking for a simple way to bring an existing web application to MySpace. I wanted to be able to place this app on a Profile page so that visitors could interact with it (similar to the Music and Video players provided by MySpace). My initial thought was to simply use an IFRAME that displayed my application. Unfortunately this turned out to be impossible as MySpace doesn’t allow IFRAMEs to be placed on Profile or Home surfaces.

So how does one quickly turn their HTML application into a MySpace application without rewriting a ton of code? Enter Microsoft Silverlight and the RadHtmlPlaceHolder control from Telerik. MySpace supports Silverlight applications, just like Flash. And with an install base somewhere around 70% now, I decided Silverlight is absolutely a viable option for my app.

The HTML Place Holder control from Telerik allows you to display HTML content within the Silverlight canvas. After checking with MySpace, I was told this was an acceptable use of Silverlight on MySpace.

I started by creating a Silverlight project. It is quite simple really, a single canvas with the HTML Place Holder control on it (set to 100% height and width) . I then added some code to handle the init parameter for the URL to display.

In my App.xaml.cs I added:

[csharp]
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage(e.InitParams);
}
[/csharp]

In my MainPage.xaml.cs I added:

[csharp]
public MainPage(IDictionary<string, string> initParams)
{
InitializeComponent();
radHtmlPlaceholder1.SourceUrl = new Uri(initParams["URI"]);
}
[/csharp]

That is the entirety of the Silverlight application. Pretty simple. I told Silverlight that the host for my Silverlight application was my existing web application, so it created the host automatically for me. I didn’t need to do anything else.

In MySpace, I added the following code to call my new Silverlight application:

[js wraplines="false"]
<div id="content"></div>

<script type="text/javascript">
var contentElement = document.getElementById("content");
var initValue = "URI= <URL TO DISPLAY>";

var object = ‘<object data="data:application/x-silverlight-2," height="100%" type="application/x-silverlight-2" width="100%"> ‘
object = object + ‘<param name="source" value="<URL TO XAP FILE>" /><param name="onError" value="onSilverlightError" /> ‘
object = object + ‘<param name="background" value="Transparent" /><param name="minRuntimeVersion" value="4.0.50401.0" /><param name="autoUpgrade" value="true" /> ‘
object = object + ‘<param name="windowless" value="true" /><param name="enableHtmlAccess" value="true" /><param name="initparams" value="’ + initValue + ‘" /> ‘
object = object + ‘<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0" style="text-decoration: none"> ‘
object = object + ‘<img alt="Get Microsoft Silverlight" src="http://go.microsoft.com/fwlink/?LinkId=161376" style="border-style: none" /> </a> </object> ‘
contentElement.innerHTML = object;
</script>
[/js]

Hopefully this helps someone else out there. Feel free to contact me with any questions.

You may also like...

2 Responses

  1. April 14, 2011

    [...] to be impossible as MySpace doesn’t allow IFRAMEs to be placed on Profile or Home surfaces. So…Read More Posted: Apr 13 2011, 09:37 AM by MarcLaFleur | with no [...]

  2. April 14, 2011

    [...] So how does one quickly turn their HTML application into a MySpace application without rewriting a ton of code? Enter Microsoft Silverlight and the RadHtmlPlaceHolder control from Telerik. MySpace supports Silverlight applications, just like Flash. And with an install base somewhere around 70% now, I decided Silverlight is absolutely a viable option for my app. Porting to MySpace using Silverlight :: MassiveScale [...]

Leave a Reply