ExternalInterface.call using actionscript “eval” only works in firefox not chrome

删除回忆录丶 提交于 2020-01-07 05:42:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!