开发者

Differentiate between F5 and browser close event in flex/actionscript

I am using the following piece of code to determine the closure of browser window and it works perfectly. But the issue arises when the user refreshes the page using "F5" or clicking browser refresh button and even in that case the same piece of code is invoked.

I would like to know if there is anyway by which i can distinguish between browser close event and refresh event using 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. Bui开发者_开发问答ld 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 );
    }
}
}

Call to above utility is done by

ExternalInterfaceUtil.addExternalEventListener("window.onunload", handleLogout, "unloadFlex");


Pseudo code:

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 );
 }
}


Write to the shared object every few seconds with current local time.

If that exists within (last few seconds + x), it was a refresh rather than close.

Let me know if you need some code examples

:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜