gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:30:02 26 4
gpt4 key购买 nike

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

最佳答案

伪代码:

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

关于apache-flex - 在 flex/actionscript 中区分 F5 和浏览器关闭事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4387212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com