F5和浏览器关闭事件的柔性/动作之间的区分 [英] Differentiate between F5 and browser close event in flex/actionscript

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

问题描述

我现在用的是下面这段code,以确定浏览器窗口的关闭和它完美的作品。但是,当用户使用F5或点击浏览器刷新按钮,即使在这种情况下,同一块code调用刷新页面的问题就出现了。

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

推荐答案

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

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

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