Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight app disappears on page refresh in IE10

UPDATE: There is a workaround to the problem. It is to force IE10 into compatibility mode by including one of the following meta tags:

<meta http-equiv="x-ua-compatible" content="IE=7" />
<meta http-equiv="x-ua-compatible" content="IE=8" />

This is not really a perfect solution for various reasons, but it eliminates the problem at least.


ORIGINAL QUESTION:
I realised a couple of months ago that there is a problem with our Silverlight application in IE10 on Windows 8 (I have not tried the IE10 preview for Windows 7). When the asp.net page hosting our SL app first loads everything works fine and the application loads as expected. If I refresh the page immediately, it also reloads as expected. But: If I focus the Silverlight application by clicking in it and THEN hit F5, it just goes blank. It is like the plugin disappears completely. If I trace the requests using Fiddler I can see that no request is issued for the xap file. I have been hoping that this would be fixed in a patch release for IE10, but so far nothing has changed. I cannot find any information about this when I try googling it. It seems highly unlikely that I should be the first person to discovered it and I am quite surprised that I am not finding more information. To reproduce the issue:

  • Create a new Silverlight application
  • Add some sort of content to MainPage.xaml, like a Button or whatever
  • Run the app in IE10 (on Win8)
  • Click anywhere within the Silverlight application. This is just to focus the plugin.
  • Refresh the page (F5)
  • Result: The Silverlight application does not load and the page is blank.

A few observations:

  • After the steps above, no amount of refreshing will bring the application back.
  • After the steps above, if I re-enter the url into the address bar and hit Enter, the application loads as expected.
  • If I enable Compatibility View in IE, the app also loads as expected. Nothing I do will reproduce the bug when compatibility view is enabled.

Now to my questions:

  1. Has anyone else observed this behaviour?
  2. If so, have you found a workaround?
like image 856
Henrik Söderlund Avatar asked Nov 21 '12 11:11

Henrik Söderlund


2 Answers

I'm seeing the same issue with my Silverlight application in IE 10.

I've tried adding the IE 8 compatibility meta tag suggested above, but this does not resolve the problem consistently. It seems to work only intermittently, after say every 5th refresh attempt?!

The only way I can see to work around this consistently is to force the Browser Mode into "IE 10 Compatibility View", and I don't think this can be done via page content (meta tag, etc.)? I've had to remove the IE 8 compatibility meta tag so that the "Compatibility View" button is available in the address bar, and then ask users to click the compatibility button, which is then remembered for the site. This results in the browser entering Browser Mode: "IE 10 Compat View" and Document Mode: "IE7 Standards". The refresh behaviour then works consistently as expected and as it used to.

This is a big problem for us. We've built our Silverlight app such that the browser refresh button is used to refresh pages/content within the app (the users stays logged in, etc.). It's really bad that we have to ask users to set our site to run in compatibility mode for the refresh functionality to work as expected.

Note that this still works as expected in Chrome. It seems silly that we might need to recommend that our users use Chrome because of this issue!

UPDATE:

A workaround for this seems to be to always load the Silverlight object into its hosting page dynamically using JavaScript.

E.g.

function onLoad() {
  var silverlightControlHost = document.getElementById("silverlightControlHost");
  silverlightControlHost.innerHTML = "<object ...

UPDATE 2:

Here is the latest code I use to work around this issue:

...
        function unloadSilverlight() {
            document.getElementById("silverlightControlHost").innerHTML = "";
        }

        function focusOnSilverlight() {
            document.getElementById("silverlightObject").focus();
        }

        function onLoad() {
            window.onbeforeunload = unloadSilverlight;
            setTimeout(focusOnSilverlight);
        }
    </script>
</head>
<body onload=" onLoad() ">
...
like image 186
Chris Avatar answered Nov 07 '22 14:11

Chris


I still had issues with the solution presented by Chris.

This works perfectly for me though:

window.onbeforeunload = function () {
            var silverlightControlHost = document.getElementById("silverlightControlHost");
            silverlightControlHost.innerHTML = "";
        }
like image 22
GugaWedge Avatar answered Nov 07 '22 14:11

GugaWedge