none
Accessing Silverlight with JavaScript in Internet Explorer doesn't work

    Question

  • Hi guys,
    I'm trying to Access my Silverlight-Application through JavaScript. In my test scenario, I define an event handler for the Silverlight plugin loaded event. Here's the code:
        function onLoaded(sender, eventArgs) {
            // Retrieve a reference to the plug-in.
            var slPlugin = sender.getHost();
            // Determine whether the 4.0 version of Silverlight is available.
            alert("Silverlight 4.0: " + slPlugin.isVersionSupported("4.0"));
        }
    That's an example I found [here (MSDN)][1].
    In Google Chrome and Firefox, everything works fine, **but not in Internet Explorer 9**!
    It's telling me, that "slPlugin" doesn't have the called method. Same if I try to access a method defined and prepared for scripting access in Silverlight:
        slPlugin.Content.Page.SomeMethod());
    That's working in Chrome and FF, but not in IE9.
    Is this maybe a security setting issue? Any ideas?
      [1]: http://msdn.microsoft.com/en-us/library/bb980127%28v=VS.95%29.aspx

    Hi guys,

    I'm trying to Access my Silverlight-Application through JavaScript. In my test scenario, I define an event handler for the Silverlight plugin loaded event. Here's the code:

        function onLoaded(sender, eventArgs) {
    
            // Retrieve a reference to the plug-in.
           var slPlugin = sender.getHost();
    
            // Determine whether the 4.0 version of Silverlight is available.
    
            alert("Silverlight 4.0: " + slPlugin.isVersionSupported("4.0"));
    
        }

    That's an example I found on the MSDN pages.

    In Google Chrome and Firefox, everything works fine, but not in Internet Explorer 9.

    It's telling me, that "slPlugin" doesn't have the called method. Same if I try to access a method defined and prepared for scripting access in Silverlight:

    slPlugin.Content.Page.SomeMethod());

    That's working in Chrome and FF, but not in IE9.

    Is this maybe a security setting issue? Any ideas?

    Thursday, May 05, 2011 4:51 AM

All replies

  • Hi Cubeless,

    Below is what I tried on my side and it works in IE 9 with and without compatibility view. Please try it on your side and check if works.

    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%" >
        <param name="source" value="ClientBin/JavascripCheckSilverlightVerson.xap"/>
        <param name="onError" value="onSilverlightError" />
        <param name="onLoad" value="onLoaded" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="4.0.50826.0" />
        <param name="autoUpgrade" value="true" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
        </a>
         </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe>

    Javascript method is same as yours.

    Additionally, please check if you set Popup blocker in IE.

     

    Best Regards,

    Monday, May 09, 2011 11:33 PM
  • Hi,


    thanks for your reply. Sadly, that's exact how I tried it. Nothing changed. It works in Chrome and FF but not in IE9. That's strange, isn't it?

    Popup blocker is deactivated. 

    Any ideas? Thanks!

    Regards,


    Tuesday, May 10, 2011 4:08 AM
  • Hi Cubeless,

    That's strange, because it works in IE9 on my side.

    Could you please zip your project, upload to SkyDrive and provide a download link here. Then i can test it on my side and verify if it is caused by your project or IE settings.

     

    Best Regards, 

    Tuesday, May 10, 2011 4:22 AM
  • Thanks for you help.

    That's my solution folder: http://cid-99a1c7efa1dce5fd.office.live.com/self.aspx/SL%20Tests/SimpleSilverlightApplication.zip

    Regards,
    cubeless 

    Tuesday, May 10, 2011 4:47 AM
  • Hi,

    I downloaded your sample and tried to host it in IIS instead of running it in Visual studio web development server and tried to access the “SimpleSilverlightApplicationTestPage.html” page and I did see the alert box.

    Could you please try the same and let us know whether it works or not.

     

    Thanks

    Thursday, May 12, 2011 8:21 AM
  • Hi,

    thanks for your help. Unfortunately that didn't change anything. The JavaScript error still occures in IE9 :-|
    Strange. Any more advices?

    Thanks! 

    Friday, May 13, 2011 2:08 AM
  • Hi,

    We tried the sample and it still works.

    Can you make sure that HTML access in enabled to Silverlight.

    You can do it by adding the following <param> tag to the <object> :-

     

    <param value="true" />

     

    Hope this helps

    Friday, May 13, 2011 3:47 PM
  • Hi, I think I missed something

     

    <param name="enableHtmlAccess" value="true" />
     
     missed name="enableHtmlAccess
    Monday, May 16, 2011 11:07 AM
  • Hi there,

    thanks, I tried that one, but it didn't help. Still no alert box in Internet Explorer.
    I think it's the browser. Maybe a corrupt installation?!

    Really strange. Undecided
     


    Tuesday, May 17, 2011 2:42 AM
  • Hi, Please perform a clean installation of IE9 from :- www.microsoft.com/India/Download-IE9 Also try running IE9 in elevated permissions and try executing the code. I hope this helps

    Tuesday, May 17, 2011 10:37 AM