专业网站设计服务在线咨询义乌企业网站
专业网站设计服务在线咨询,义乌企业网站,网站建设推广专家服务,企业网站 模版FROM : http://blog.ityao.com/archives/581 如果想用Flash/Flex监听浏览器的关闭事件#xff0c;可以通过JavaScript的window.onbeforeunload事件进行监听然后JS调用Flash中的函数。在swf所在页面的JavaScript中添加如下代码JS中代码#xff1a;#xff08;这里设定swf文件… FROM : http://blog.ityao.com/archives/581 如果想用Flash/Flex监听浏览器的关闭事件可以通过JavaScript的window.onbeforeunload事件进行监听然后JS调用Flash中的函数。在swf所在页面的JavaScript中添加如下代码JS中代码这里设定swf文件名为TestFlashwindow.onbeforeunload onbeforeunloadHandler; //添加响应函数function onbeforeunloadHandler() { var swfRef document.TestFlash|| window.TestFlash; //获取swf的引用if ( swfRef ) { warning swfRef.windowCloseHandler(); // 调用Flash中的windowCloseHandler函数 return “Are you sure to close this page?”;}} AS中代码(在程序初始化的函数中添加,例如Flex的creationComplete事件中)if(flash.external.ExternalInterface.available){ flash.external.ExternalInterface.addCallback(‘windowCloseHandler’,externalWindowCloseHandler);//使用ExternalInterface向JS中添加调用函数}/** 告诉服务器该flash已经被关闭*/protected function externalWindowCloseHandler():void{ //use HttpService in Flexvar http:HTTPService new HTTPService();http.url ‘http://localhost/testphp/index.php?fromflexcloseByHTTPService’;http.send();//use URLLoader in AS3var request:URLRequest new URLRequest(‘http://localhost/testphp/index.php? fromflexcloseByUrlLoader’);var urlLoader:URLLoader new URLLoader();urlLoader.load(request);}Flex中可以在FlashBuilder的HTML模板上添加JS代码修改html-template中的index.template.html文件在其中添加JS代码window.onbeforeunload onbeforeunloadHandler; //添加响应函数function onbeforeunloadHandler() { var swfRef document.${application}|| window.${application}; //获取swf的引用if ( swfRef ) { warning swfRef.windowCloseHandler(); // 调用Flash中的windowCloseHandler函数 return “Are you sure to close this page?”;}} 在AS中直接注入JS代码如果不想更改HTML文件也可以在AS中直接书写JS代码注入到HTML文档中if(flash.external.ExternalInterface.available){var jsStr:String; jsStr ‘eval(\’window.onbeforeunload onbeforeunloadHandler;’ ‘function onbeforeunloadHandler(){‘ ‘var swfRef document.’FlexGlobals.topLevelApplication.className’ || window.’FlexGlobals.topLevelApplication.className’;’ ‘swfRef.windowCloseHandler();’ ‘return “Are you sure to close this page?”;’ ‘}\’);flash.external.ExternalInterface.call(jsStr); flash.external.ExternalInterface.addCallback(‘windowCloseHandler’,externalWindowCloseHandler);}移除该监听只要设置window.οnbefοreunlοadnull即可AS中可以这样写flash.external.ExternalInterface.call(‘eval(\’window.onbeforeunload null\’));flash.external.ExternalInterface.call(‘eval(\’location.reload();\’)); //再执行刷新浏览器的命令源文件 TestFlex.zipFrom - http://blog.ityao.com/archives/581 转载于:https://www.cnblogs.com/Athrun/archive/2010/11/08/1871604.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/89686.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!