I have a Flash movie embedded with swfobject in a html container.
Through ExternalInterface I have registered a Javascript function to fire callback to my flash app.
ExternalInterface.addCallback("notifyClose", notifyOnClose );
The Javascript function is added as an event listener to fire onbeforeunload.
<script language="JavaScript">
function getSWF(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1){
return window[movieName];
}else { return document[movieName];}
}
var bye = function() {
getSWF('flashContainer').notifyClose('> WE ARE CLOSING APP!');
//alert('WE ARE CLOSING APP!.');
};
var hola = function(){
getSWF('flashContainer').notifyClose('> WE ARE opening APP!');
alert('WE ARE opening APP!.');
};
if(window.addEventListener) {
window.addEventListener('load', hola,false);
window.addEventListener('beforeunload', bye, false);
} else if (window.attachEvent) {
window.attachEvent('onload', hola);
window.attachEvent('onbeforeunload', bye);
}
</script>
I have tested in Firefox and IE. Firefox works as expected but not in IE.
In IE I get notified in Flash with the onload message, but not onbeforeunload.
Is it some kind of sandbox restriction? Just bad code?
The problem is the “on” in your code below in the attachEvent().
Try something like the code below for your Event Listener code and see the following link for more information: http://bytes.com/topic/javascript/answers/147027-addeventlistener-function-ie