问题
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.
回答1:
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;
}
}
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/17727766/how-to-check-flash-plugin-is-blocked-in-chrome