4

我正在使用以下代码来确定浏览器窗口的关闭,并且它运行良好。但是,当用户使用“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");

4

2 回答 2

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 );
 }
}
于 2010-12-08T15:31:11.833 回答
0

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

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

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

:)

于 2011-07-11T01:25:15.870 回答