Newer Version Available
Using Events with the Lightning Console JavaScript API
Events are fired from JavaScript controller actions. Events can contain attributes that can be set before the event is fired and read when the event is handled. Each event that works with Lightning console apps returns attributes that can be read once the event is fired. See the reference section of this guide for a list of attributes returned by each event.
To use console events, set up a handler in your Aura component. The following handler, for example, listens for the lightning:tabCreated event, and calls the onTabCreated function in the component’s controller when the event occurs.
1<aura:handler event="lightning:tabCreated" action="{! c.onTabCreated }"/>Let’s look at a more fleshed out example. The following component uses the lightning:tabClosed event.
1<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
2<aura:handler event="lightning:tabClosed" action="{! c.onTabClosed }"/>
3</aura:component>When a tab is closed, the event handler calls onTabClosed in the component’s controller, which logs the tabId of the closed tab.
1({
2 onTabClosed : function(component, event, helper) {
3 var tabId = event.getParam("tabId");
4 alert(“Tab with tabId of “ + tabId + “ was just closed.”);
5 }
6})You can use Lightning console events with the Workspace API and Utility Bar API to customize your users’ experience. You can, for example, give a tab focus when it’s refreshed, or notify the user with a modal dialogue when a tab is replaced.