是否可以在 flash 横幅中运行 html<脚本>
Is it possible to run html <script> in the flash banner?
我想直接"从flash(swf)横幅"运行一些javascript代码。
可能吗?我该如何管理呢?
为了能够使用 ActionScript 在 DOM 中注入 JS 脚本,然后通过注入的函数进行通信,您可以执行以下操作:
1) 导入外部类。
import flash.external.ExternalInterface;
2) 声明一个包含所有 JS 函数的常量变量:
private const script_js :XML =
<script>
<![CDATA[
function() {
AJXFNC = {
ajaxFunction:function(_url){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari, Chrome
ajaxRequest = new XMLHttpRequest();
ajaxRequest.open("GET", _url, true);
ajaxRequest.send(null);
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
ajaxRequest.open("GET", _url, true);
ajaxRequest.send();
} catch (e){
// Something went wrong
return false;
}
}
}
}
}
}
]]>
</script>;
3) 将 JS 注入到 DOM:
try {
if( ExternalInterface.available )ExternalInterface.call( script_js );
} catch( error:Error ) {
trace("ExternalInterface is not available");
}
4)调用函数:
ExternalInterface.call( "AJXFNC.ajaxFunction", "http://www.google.com" );
我已将该技术粘贴到此答案中,因为我通常不信任博客的正常运行时间,但所有权利归Adi Feiwel所有,因为写了这个:http://todepoint.com/blog/2011/08/01/injecting-and-calling-js-functions-from-within-flash-using-external/
相关文章:
- 我的HTML按钮没有在Javascript中运行
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 如何在angularJS中运行for循环而不使用html标记
- 有条件地运行javascript函数-Razor,HTML
- html代码没有在记事本++上运行
- HTML/JS github页面项目没有't在使用firefox运行时加载图像或声音
- Disqus的计数.js脚本在索引中无法正常运行.html与react.js网站
- 如何运行在一个充满html的字符串中定义的javascript
- HTML 运行时创建代码非常慢
- 如何从 HTML 运行应用程序
- 正文加载上的 HTML 运行 href 链接
- 从Javascript和HTML运行Unix命令
- Beaglebone Black Rev C Debian,从html运行PHP程序
- 使用Html.运行时BeginForm
- $compile不更新动态生成的HTML运行时
- 如何从HTML运行另一个程序
- 如何独立于HTML运行Javascript文件
- 如何使用ng-bind-html运行javascript
- 从按钮html运行bash脚本
- 为动态插入的HTML运行javascript函数