在flex / actionscript中区分F5和浏览器关闭事件

时间:2010-12-08 12:06:27

标签: flex actionscript adobe browser-refresh

我正在使用以下代码来确定浏览器窗口的关闭,它完美地运行。但是当用户使用“F5”或单击浏览器刷新按钮刷新页面时会出现问题,即使在这种情况下也会调用相同的代码。

我想知道无论如何我可以使用actionscript区分浏览器关闭事件和刷新事件

package utils
{
import flash.external.ExternalInterface;

public class ExternalInterfaceUtil
{
    public static function addExternalEventListener( qualifiedEventName:String, callback:Function,callBackAlias:String ):void
    {
        // 1. Expose the callback function via the callBackAlias
        ExternalInterface.addCallback( callBackAlias, callback );
        // 2. Build javascript to execute
        var     jsExecuteCallBack:String = "document.getElementsByName('"+ExternalInterface.objectID+"')[0]."+callBackAlias+"()";
        var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){"+jsExecuteCallBack+"};}";
        // 3. Execute the composed javascript to perform the binding of the external event to the specified callBack function
        ExternalInterface.call( jsBindEvent );
    }
}
}

通过

调用上述实用程序

ExternalInterfaceUtil.addExternalEventListener(“window.onunload”,handleLogout,“unloadFlex”);

2 个答案:

答案 0 :(得分:1)

伪代码:

public static function addExternalEventListener( qualifiedEventName:String, callback:Function,callBackAlias:String ):void
{
   if(lastKeyPressed.KeyCode != 116)
   {
    // 1. Expose the callback function via the callBackAlias
    ExternalInterface.addCallback( callBackAlias, callback );
    // 2. Build javascript to execute
    var     jsExecuteCallBack:String = "document.getElementsByName('"+ExternalInterface.objectID+"')[0]."+callBackAlias+"()";
    var jsBindEvent:String = "function(){"+qualifiedEventName+"= function(){"+jsExecuteCallBack+"};}";
    // 3. Execute the composed javascript to perform the binding of the external event to the specified callBack function
    ExternalInterface.call( jsBindEvent );
 }
}

答案 1 :(得分:0)

使用当前本地时间每隔几秒写入共享对象。

如果它存在于(最后几秒+ x)内,那么它是刷新而不是关闭。

如果您需要一些代码示例,请告诉我

:)