I have a Silverlight application on an HTML page. The SL plugin is located in the HTML "object" tag. When a user closes a webpage, I want to call a function inside my Silverlight application. The code looks something like this:
(simplified) HTML:
<div id="silverlightControlHost"> <object id="MyApp" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/MyApp.xap" /> ... </object><iframe id="_sl_historyFrame"></iframe></div>
Javascript Code:
<script type="text/javascript"> window.onbeforeunload = confirmExit; function confirmExit() { var control = document.getElementById("MyApp"); var message = control.content.BrowserIntegration.MyAppFunction(); if (message) { return message; } } </script>
It worked, and it no longer works, at least in Internet Explorer 8. The content property of the HTML object (control.content) is undefined. Itβs strange. Has a variable recently occurred for this property? I am sure that he worked 2 months ago, and that he worked well long before that. The website is located on my trusted sites, and I did not find the settings in IE that I have changed since (maybe one or two, but, scanning the list, I did not find anything).
When I do a test with the "onLoad" event of the HTML object, the content is already undefined.
I do not know if the anomaly is a fact that it worked before or that it does not work now. But if someone can tell me how to make it work now, it will make my day.
source share