共用方式為


ON_SESSION_CLOSED事件 (應用程式設定檔管理員)

當工作階段關閉時,用戶端會叫用此事件。 此事件可讓您執行清除工作或更新應用程式狀態以回應會話關閉。 ON_SESSION_CLOSED事件會採用下列 eventData:

事件資料 Description
sessionId 已關閉之工作階段的階段作業識別碼。

Example


// Define a handler function that's triggered when a session is closed
let sessionClosedHandlerFunction = function(eventInput) {
    // Log the ID of the closed session to the console
    console.log("Session closed: " + eventInput.data.sessionId);
};
// Retrieve the event topic specific to session closing from the API
let sessionCloseTopic = Microsoft.Apm.getEventPublisherTopic("ON_SESSION_CLOSED");
// Create a new broadcast channel to subscribe to session close events
let sessionCloseSubscriber = new BroadcastChannel(sessionCloseTopic);
// Attach the session closed handler function to the message event of the subscriber
sessionCloseSubscriber.onmessage = sessionClosedHandlerFunction;

備註

程式碼範例會利用 廣播通道API - Web API,在不同檔之間進行通訊,例如相同來源的頁面或iframe。 請確定它與您的自訂專案相容,因為此 API 的支援可能會有所不同。