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