问题
Chrome doesn't want to let me access javascript from swf file directly in the URL bar (I know that isn't best practice, but that's what I am trying to accomplish):
Given:
/file.swf?cmd=alert();
With the following code (snippet):
flash.external.ExternalInterface.call("eval", cmd);
This only works in Firefox and not in Chrome. I am taking this approach because in chrome the actionscript 2 way to run JS was to use getURL("Javascript:...., however this doesn't work in Chrome either anymore.
Is there a way around this (by calling the file directly in the browser as opposed to be embedded in a page?)- I have my reasons!
回答1:
Try creating a custom function the proxies the 'eval' function. Try this in JS...
function exec_code( $value ) {
window.eval( $value );
}
... and this in AS.
var value:String = "[JavaScript Code to execute]";
if ( ExternalInterface.available ) ExternalInterface.call( 'exec_code', value );
来源:https://stackoverflow.com/questions/18837959/externalinterface-call-using-actionscript-eval-only-works-in-firefox-not-chrom