このイベントは、セッションが閉じられたときにクライアントによって呼び出されます。 このイベントは、クリーンアップ タスクを実行したり、セッションの終了に応答してアプリケーションの状態を更新したりする機会を提供します。 イベントON_SESSION_CLOSED、次のeventDataを受け取ります。
| eventData | Description |
|---|---|
| sessionId | 近かったセッションのセッション ID。 |
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 のサポートは異なる場合があるため、カスタマイズと互換性があることを確認してください。