在 flex/actionscript 中区分 F5 和浏览器关闭事件 [英] Differentiate between F5 and browser close event in flex/actionscript

查看:24
本文介绍了在 flex/actionscript 中区分 F5 和浏览器关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来确定浏览器窗口的关闭,它运行良好.但是,当用户使用F5"或点击浏览器刷新按钮刷新页面时就会出现问题,即使在这种情况下调用了同一段代码.

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.

我想知道是否有任何方法可以使用 actionscript 区分浏览器关闭事件和刷新事件

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

对上述实用程序的调用由

Call to above utility is done by

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

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

推荐答案

伪代码:

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

这篇关于在 flex/actionscript 中区分 F5 和浏览器关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆