ON_TAB_SWITCH acara

Peristiwa ini dipanggil oleh klien apabila tab ditukar kepada tab lain. Acara ini membolehkan pengendali bahagian pelanggan bertindak balas terhadap suis tab, mengemas kini antara muka pengguna atau keadaan dalaman mengikut keperluan. ON_TAB_SWITCH acara mengambil eventData berikut.

eventData Description
previousSessionId ID sesi tab sebelumnya.
sebelumnyaTabId ID tab tab sebelumnya.
SessionId ID sesi tab yang kini difokuskan.
tabId ID tab yang kini difokuskan.

Contoh


// Define a handler function that's triggered when the tab is switched
let tabSwitchedHandlerFunction = function(eventInput) {
    // Log the previous and new session IDs and tabs IDs to the console
    console.log("Previous session:  " + eventInput.data.previousSessionId + 
                " Previous tab: " + eventInput.data.previousTabId +
                " Current session: " + eventInput.data.sessionId + 
                " Previous tab: " + eventInput.data.tabId );

}; 

// Retrieve the event topic specific to tab switching from the API
let tabSwitchTopic = Microsoft.Apm.getEventPublisherTopic("ON_TAB_SWITCH");
// Create a new broadcast channel to subscribe to tab switch events
let tabSwitchSubscriber = new BroadcastChannel(tabSwitchTopic);
// Attach the tab switched handler function to the message event of the subscriber
tabSwitchSubscriber.onmessage = tabSwitchedHandlerFunction; 

Nota

Sampel kod menggunakan API Saluran Siaran - API Web untuk berkomunikasi antara dokumen yang berbeza seperti halaman atau iframe yang berasal dari asal yang sama. Pastikan ia serasi dengan penyesuaian anda kerana sokongan untuk API ini boleh berbeza-beza.