當會話切換至另一個會話時,用戶端會叫用此事件。 此事件允許客戶端處理程序對會話切換做出反應,根據需要更新使用者介面或內部狀態。 ON_SESSION_SWITCH事件會採用下列 eventData:
| 事件資料 | Description |
|---|---|
| previousSessionId | 前一個階段作業的階段作業 ID。 |
| newSessionId | 現在焦點的工作階段識別碼。 |
Example
// Define a handler function that's triggered when the session is switched
let sessionSwitchedHandlerFunction = function(eventInput) {
// Log the previous and new session IDs to the console
console.log("Previous session: " + eventInput.data.previousSessionId +
" - Current session: " + eventInput.data.newSessionId);
};
// Retrieve the event topic specific to session switching from the API
let sessionSwitchTopic = Microsoft.Apm.getEventPublisherTopic("ON_SESSION_SWITCH");
// Create a new broadcast channel to subscribe to session switch events
let sessionSwitchSubscriber = new BroadcastChannel(sessionSwitchTopic);
// Attach the session switched handler function to the message event of the subscriber
sessionSwitchSubscriber.onmessage = sessionSwitchedHandlerFunction;
備註
程式碼範例會利用 廣播通道API - Web API,在不同檔之間進行通訊,例如相同來源的頁面或iframe。 請確定它與您的自訂專案相容,因為此 API 的支援可能會有所不同。