Javascript crossdomain workaround

Apr 14, 2011 at 7:47 PM

I have an application on one domain and I'm loading my xap-file from another domain. The consequense is that I can't use the Javascript API.

When I run the sample below the onPlayerReady function is never called, but if I run the code on the same domain as the xap file all is fine.

Is there a workaround for this?

 

Example:

Code running on domain domainname1.com

window.onload = function()
        {
            onPlayerReady = function(player) {
               var Player = player;
               Player.MediaOpened = function () { alert(1)};
               Player.MediaEnded = function () { alert(2)};
            }
           
            Silverlight.createObjectEx({
                source: "http://domainname2.com/SMFPlayer.xap",
                parentElement: "myDiv",
                id: "id1",
                properties: {
                    width: "100%",
                    height: "100%",
                    background: "black",
                    alt: "",
                    version: "4.0.50401.0"
                },
                events: {
                    onError: null,
                    onLoad: null
                },
                initParams: "source=http://domainname2.com/Wildlife.wmv",
                context: null
            });
        }

Apr 14, 2011 at 8:25 PM

You will probably want to use Html EnableHtmlAccess param. This is meant for these types of scenarios

http://msdn.microsoft.com/en-us/library/cc838264(v=vs.95).aspx

Apr 14, 2011 at 9:43 PM
Edited Apr 14, 2011 at 9:59 PM

Thanks!

It only solved my problem partially, though.

My onPlayerReady function is run but the eventhandler functions are never called :-(

When I run my code in explorer, I get the following error:

System.InvalidOperationException: Scriptable access is disabled.
   at System.Windows.Hosting.ManagedHost.VerifyScriptableEnabled()
   at System.Windows.Hosting.ManagedHost.InvokeScriptableMember(IntPtr pHandle, Int32 nMemberID, Int32 nInvokeType, Int32 nArgCount, ScriptParam[] pArgs, ScriptParam& pResult, ExceptionInfo& pExcepInfo)

Apr 15, 2011 at 12:17 AM

Hmm.. looks like there is another setting in the manifest that may help

http://msdn.microsoft.com/en-us/library/cc645023(VS.95).aspx

 

but from reading that it seems like it does have some drawbacks

Apr 18, 2011 at 3:33 PM

Thanks!

It has drawbacks, but it works :-)

 

Apr 18, 2011 at 4:21 PM

I'd be interested into knowing exactly what the drawbacks where, what worked and what didn't and what things you had to do differently? I'm going to be doing another project soon that is going to run into this issue