53924

Silverlight Web Part not loading until user clicks on page

Question:

I am maintaining a Silverlight 4 application that runs as Web Part in SharePoint. However, I have an issue with loading it in Internet Explorer (versions 10 & 11). The user must click on the web page or hit tab for the Silverlight web part to actually load. However, this is not an issue in Chrome. There is a silverlight.js script runs when the page initially loads, but it appears (in Fiddler) that the XAP isn't getting called until the user clicks or or hits tabs on the page. So far, I have tried loading the page with and without ActiveX. Also I have tried running the page with my own JavaScript file to click and put focus on various elements in the page, but so far no luck.

I noticed this issue was briefly referenced in a comment on the following Stack Overflow question: <a href="https://stackoverflow.com/questions/3323391/why-wont-my-silverlight-application-load-in-internet-explorer" rel="nofollow">Why won't my Silverlight Application load in Internet Explorer?</a>, but I have yet to come across any resolution to this particular issue.

Any suggestions?

Answer1:

I've read if you set the height and width of the object tag or remove the object tag from its DIV container that this can solve the issue. If this is easier for you, then you might want to try this first.

However, I solved the issue with a little javascript. I used JQuery, but you could probably do something similar with pure javascript.

This is what my code looked like before the modification:

<div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%" id="silverObj"> <param name="source" value="../MySilverlightApp.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="4.0.50826.0" /> <param name="autoUpgrade" value="true" /> <a href="http://www.microsoft.com/getsilverlight/get-started/install/default.aspx" 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> </div>

This is what the modified code looks like, basically I just removed all the content from the #silverlightControlHost DIV and then put all the content back into the DIV after the page load via JQuery:

<script type="text/javascript"> $(document).ready(function() { $("#silverlightControlHost").html("<object data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='100%' height='100%' id='silverObj'><param name='source' value='../MySilverlightApp.xap'/><param name='onError' value='onSilverlightError' /><param name='background' value='white' /><param name='minRuntimeVersion' value='4.0.50826.0' /><param name='autoUpgrade' value='true' /><a href='http://www.microsoft.com/getsilverlight/get-started/install/default.aspx' 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>"); }); </script> <div id="silverlightControlHost"> </div>

For reference, I did not see this issue on IE 8 but then on IE 11 using the same version of SharePoint, same version of Silverlight, same code, same everything I was having the issue that the Silverlight control would not load until you click on the empty space where it should be. After I clicked on it, everything would load just fine. I first tried to click on the object using JQuery, but that did not work. It required an actual user to click on it, not a programatic click. The above Javascript/JQuery solution solved this issue and now it loads when the page loads as it did in IE 8. I also tested this fix in both IE 8, IE 11, and Chrome Version 42.0.2311.90 m (64-bit). My Silverlight app is loading in a web part on a Sharepoint 2010 site.

Recommend

  • How do I install these PHP extensions on Ubuntu?
  • Display Current Video in Windows Phone 8 using AudioVideoCaptureDevice?
  • Hatch area using pcolormesh in Basemap
  • OpenOptionsMenu not working with ActionBarSherlock Custom SubMenu
  • How to remove left and right margins from all wrapped rows in flexbox (without nth-child or js)
  • IE11 textarea loses focus if another textarea is disabled
  • Get the last date of each month in a list of dates in Python
  • How do I add a File Type Association in a Windows Phone 8.1 app manifest?
  • Where these are stored?
  • Outlines on links in IE9 remains when focus is changed
  • How to getText() from the input field of an angularjs Application
  • Sending keystrokes/mouse clicks to a Java program with Autohotkey
  • D3 get axis values on zoom event
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Textfile Structure (tables)
  • Display images in Django
  • Problem deserializing objects from cache on MyBatis 3/Java
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Ajax Loaded meta Tags
  • Xamarin Forms - UWP Fonts
  • Different response to non-authenticated users and AJAX calls
  • C# - Serializing and deserializing static member
  • How to set/get protobuf's extension field in Go?
  • Sending data from AppleScript to FileMaker records
  • Knitr HTML Loop - Some HTML output, some R output
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • How to show dropdown in excel using jrxml (jasper api)?
  • Arrays break string types in Julia
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • How to include full .NET prerequisite for Wix Burn installer
  • SQL merge duplicate rows and join values that are different
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • LevelDB C iterator
  • Is it possible to post an object from jquery to bottle.py?
  • Can't mass-assign protected attributes when import data from csv file
  • reshape alternating columns in less time and using less memory