ExternalInterface.call using actionscript “eval” o

2019-08-31 06:38发布

问题:

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 );