External Interface Calls To Flash Not Working in IE9 - javascript

We have a flash game embedded in a web page (using SWFObject v2.2) and there are some links on the page that call into the flash in the following manner:
window.document["flashObjectId"].flashMethod();
This has worked great on all browsers we have tried including IE7 and 8, however on IE9 it generates the following error: "SCRIPT438: Object doesn't support this property or method".
It does work in compatibility mode so I tried adding a meta tag to tell IE9 to use compatibility mode by default, however that didn't work because our game runs in an IFrame within Facebook.
I have tried referencing the flash object every way I could think of in the Javascript but I always get that same error message in IE9. If anyone has any information that could help me get this to work in IE9 I would really appreciate it!

This is probably the reason for your problem and solution is also provided here:
http://msdn.microsoft.com/en-us/library/gg622942%28v=VS.85%29.aspx

I had same problem, but i did not use SWFObject or AC_RunActiveContent.js.
My solution was: swf published with HTML and AC_RunActiveContent.js. Then i replaced my current code with exported from flash and it started working.

What do you think about this?
function getFlashObject(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
//alert("IE");
if (typeof (window[movieName].flashMethod) == 'function') {
// < IE9
movie = window[movieName];
}
else if (typeof (document[movieName].flashMethod) == 'function') {
// >= IE9
movie = document[movieName];
}
}
else {
// NON IE
movie = document[movieName];
}
return ((movie) ? true : false);
}
$(document).ready(function () {
if(getFlashObject("flashObjectId")) {
movie.flashMethod();
} else {
alert("Failed to initialize");
}
}

Related

Modern or Non-deprecated way to detect flash player with js/jquery?

First of all, sorry for ressurrecting this question here.
I've been trying for two days how to reach this job using javascript/jquery and i think i've read all stack overflow and other blogs posts about that, so please, don't mark it as duplicated because I can't use out-dated scripts from 2012 now in 2017.
I've a single page that redirects to a third party e-learning platform where some content needs flash to work. Many users don't care about which software is installed on their machines (what a new, huh) so i need to detect it and show the tipical message "please install/update flash player clicking here", but i cannot find a "modern" script/way to do this, in any place, simplified, if possible.
All scripts i've tried are deprecated or returns false in all browsers, even i've newest version of flash installed and active.
Anny help will be appreciated (except links to older posts or scripts that don't work nowadays, obviously).
Thanks a lot!
There is a simple way to check for Flash since all the installed and enabled plugins will be listed in navigator.plugins;
Note that if a plugin is installed, but not enabled, it will not be detected in the navigator.plugins array. There is NO way to detect this using Javascript (this Question which confirms the same).
Having said that, use the following function isFlashEnabled(); to detect Flash :
<html>
<script>
if(isFlashEnabled())
{ document.write('Flash is installed (but may need to be enabled)'); }
else { document.write('Flash is either not installed or disabled'); }
function isFlashEnabled()
{
var flash = navigator.plugins.namedItem('Shockwave Flash');
if (!flash) { return 0; }
else { return 1; }
}
</script>
<body> <embed src="https://www.w3schools.com/tags/helloworld.swf"> </body>
</html>
You can get an array which contains all installed plugins of a browser like this:
var plugins = navigator.plugins;
Then you can then check if the array contains the flash plugin.
From https://developer.mozilla.org/de/docs/Web/API/NavigatorPlugins/plugins:
function getFlashVersion() {
var flash = navigator.plugins.namedItem('Shockwave Flash');
if (typeof flash != 'object') {
// flash is not present
return undefined;
}
if(flash.version){
return flash.version;
} else {
//No version property (e.g. in Chrome)
return flash.description.replace(/Shockwave Flash /,"");
}
}

JavaScript Methods Not Executing Consistently In Mobile Safari vs. Android Chrome

I have a method in JavaScript that looks as follows:
function onAction() {
getValue1();
getValue2();
getValue3();
}
When I call onAction() I see two different behaviors between Mobile Safari and Android Chrome. In Safari, I get the values for all three methods. On Android Chrome, I only get the value of the last method. It doesn't matter which one is last. I suspected it may be an execution timing issue and attempted the following:
function onAction() {
new Promise(function(resolve,reject) {
resolve(1);
})
.then(function() {
getValue1();
})
.then(function() {
getValue2();
})
.then(function() {
getValue3();
});
}
Again, it works fine in Mobile Safari, but not Android Chrome.
I'm sure I'm missing something obvious, but it's eluding me. If it matters, the getValue* functions are used to get values via each platform's mechanism for Native Code->JavaScript bridging.
Any help is appreciated. Please let me know if I can supply any more information.
Regards,
Rob
**Additional Info **
The getValueX functions don't return any values. They trigger values to be pushed over to the native wrapper:
function getReaderSDKVersion() {
var message = {'action' : MPDataEnum.SDKVersion};
raiseMessage(message);
}
function raiseMessage(message) {
if (isPlatformiOS()) {
window.webkit.messageHandlers.interOp.postMessage(message);
} else {
var url = "mpcard://runMethod#" + JSON.stringify(message);
window.location.href = url;
}
}
The issue is answered here:
Triggering shouldStartLoadWithRequest with multiple window.location.href calls
Whereas this was an issue in most browsers, it doesn't appear to affect Mobile Safari now.

In IE10 ('localStorage' in window) condition is true but localStorage is undefined?

Browsing all the questions/answers here but can't find a resolution to my problem. The condition ('localStorage' in window) returns true but object of localStorage itself remains undefined. <!DOCTYPE html> set properly, can't get it working. I am using IE10. Tried watch it via developer tools, the same result.
Any ideas here?
Edit
function storageAvailable() {
try {
return 'localStorage' in window && window['localStorage'] !== null && window['localStorage'] !== undefined;
} catch (e) {
return false;
}
}
Based on the same issue in IE9 I would like to update the question: is there any workaround? I cannot use even static server on the machine I need to test on.
I'm gonna go out on a limb here and say that your problem is that local storage wont work on file:// protocol in ie, so you need some kind of server.

how to check flash plugin is blocked in Chrome

How can I check using jquery or javascript whether flash plugin is blocked in chrome?
We can check for disabled flash plugin using below
((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
In Chrome you can disable plugin individually by clicking on disable individual plugin. Then if we disable plugin individually, above query works and return false. But If we block all plugin it will return true only.Hence my concern is how to detect a plugin has been blocked.
You could use something like swfobject to handle flash detection, but something like this should also work;
var flashAvailable = false;
try {
var flash = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if(flash) {
flashAvailable = true;
}
}
catch(e) {
if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) {
flashAvailable = true;
}
}
I have found that the only reliable method is to get the individual Flash element to alert the browser that it is enabled, ie. that it is not blocked.
I do this using the following code at the start of my Flash file:
import flash.external.ExternalInterface;
ExternalInterface.call('flashHasLoaded','my-identifier');
This then triggers a JavaScript function in the browser:
<script type="text/javascript">
function flashHasLoaded( optionalIdentifier ){
alert("A flash file has started running");
if(optionalIdentifier == "specific-thing") alert("Specific thing loaded - do something");
}
</script>
Remember that this wont trigger right away, only once the Flash has loaded and started to run.
The only way I could think of checking if the browser is blocking the plugin is to make a call to the plugin and see if it returns. In your case, these steps:
Check the flash plugin is installed.
Initialize your flash swf as usual.
Call a function through the Flash External Interface that is designed to just tell you if the plugin is responding.
If it responds, carry on as normal.
If it does not respond, fall back to a javascript solution ideally.
Because it's a browser security thing you do not have direct access to an api that can tell you if your desired plugin is being blocked. I think this may be the only solution available right now. Also note, that the latest version of chrome (54.0.2840.59 right now) chrome is blocking all flash if it's running in an iframe.

JQuery security error in Opera and Internet Explorer

I am developing an app for social network which works in IFrame. The app works just fine in Google Chrome and Microsoft Firefox browsers, but in Opera 12.15 JQuery library v1.10.1 fails to load with security error Unhandled error: Security error: attempted to read protected variable on line 1513.
The screenshot is here:
It looks like the same bug exists in Internet Explorer 10.
How to deal with it?
UPDATE:
I have made dirty hack by commenting the lines 1513-1517 in the code of jquery:
// Support: IE>8
// If iframe document is assigned to "document" variable and if iframe has been reloaded,
// IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
/*if ( parent && parent.frameElement ) {
parent.attachEvent( "onbeforeunload", function() {
setDocument();
});
}*/
The functionality of my app seems to work now, maybe it is necessary to create issue in JQuery repo...
Bug report was created - http://bugs.jquery.com/ticket/13980.
Bug is now fixed.
Add this before you include JQuery:
var isIE11 = !!(navigator.userAgent.match(/Trident/) && !navigator.userAgent.match(/MSIE/));
if (isIE11) {
if (typeof window.attachEvent == "undefined" || !window.attachEvent) {
window.attachEvent = window.addEventListener;
}
}
Hope it helps, It worked for me.

Categories

Resources