首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex 封锁浏览器

2012-10-25 
flex关闭浏览器在Actionscript 2及以前,要打开任何网址,只需调用全局函数getURL()即可。在Actionscript 3中

flex 关闭浏览器
在Actionscript 2及以前,要打开任何网址,只需调用全局函数getURL()即可。在Actionscript 3中,已经取消了getURL()这个全局函数,取而代之的是flash.net包中的函数navigateToURL(),API格式如下:
public function navigateToURL(request:URLRequest,window:String=null):void

如果你想在flex应用中关闭浏览器窗口,可以利用navigateToURL调用javascript来实现,网上搜索得到如下示例:
引用


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function closeIE():void{
var request:URLRequest = new URLRequest("javascript:window.close()");
navigateToURL(request,"_self");
}
]]>
</mx:Script>
<mx:Button textAlign="center" label="Close current IE" click="closeIE()"/>
</mx:Application>


测试一下,你会发现关闭窗口之前会弹出确认的信息提示。如果想关闭窗口且不弹出信息窗口,将上述代码稍加改动(改动request变量声明那一行,注意黑体部分)即可实现。

引用


var request:URLRequest = new URLRequest("javascript:window.opener=null;window.close()");


实际上还可以更简单一些,如下:

引用

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">     <mx:Button textAlign="center"      label="Close current IE"      click="navigateToURL(new URLRequest('javascript:window.opener=null;window.close()'),'_self')"/>     </mx:Application>


flex可以通过调用js代码来实现关闭浏览器窗口。代码如下:
Alert.buttonWidth=60;Alert.yesLabel="是";Alert.cancelLabel="否";var alert:Alert=Alert.show("确定要退出系统吗?","提示",Alert.YES|Alert.CANCEL,this,function(event:CloseEvent):void{switch(event.detail){case Alert.YES://javascript:window.opener=null;window.close()");//没有确认对话框//var request:URLRequest = new URLRequest("javascript:window.close()");//有确认对话框//如果不加window.open('','_self') 则在IE7下会自动提示 是否关闭当前窗口 var request:URLRequest = new URLRequest("javascript:window.opener=null;window.open('','_self');window.close()");navigateToURL(request,"_self");break;case Alert.CANCEL:break;}},null,Alert.CANCEL);PopUpManager.centerPopUp (alert);var newX:Number = (Application.application.width-alert.width)/2;           var newY:Number = (Application.application.height-alert.height)/2;           alert.move(newX,newY);

注意:

    window.open('','_self');如果不加这句代码,在IE6下测试是正确的,但是在IE7下会出现问题。IE7下点击Flex的确定按钮后,浏览器会弹出一个提示框提示是否关闭窗口。


参考:http://blog.csdn.net/ocean20/archive/2009/06/19/4279795.aspx
     http://yunzhongxia.iteye.com/blog/757764

热点排行