We hope the following code helps you:
btn = { id: 'button', width : 130, height : 35, text: 'Button', listeners : { click : function(){ var activetab = Ext.getCmp('extabs').getActiveTab(); var activetabid = activetab.getId(); if(activetabid == 'regiontab'){ alert('Clicked button in region Tab'); }else if(activetabid == 'countrytab'){ alert('Clicked button in country Tab'); } } } }; toolbar = Ext.create('Ext.Toolbar',{ id:'extoolbar', width : 350, height : 40 }); country = { id : 'countrytab', title : 'Country' }; region = { id : 'regiontab', title : 'Region' }; var exTabs = Ext.create('Ext.tab.Panel',{ id : 'extabs', activeTab : 0, width : 350, plain : true, style : 'background:none', items : [region,country], listeners : { beforerender : function(){ Ext.getCmp('regiontab').add(toolbar); toolbar.add(btn); }, tabchange : function(tp,newTab,currentTab){ if(newTab.getId()=='countrytab'){ toolbar.removeAll(); Ext.getCmp('countrytab').add(toolbar); toolbar.add(btn); } if(newTab.getId()=='regiontab'){ toolbar.removeAll(); Ext.getCmp('regiontab').add(toolbar); toolbar.add(btn); } } } }); exWindow = Ext.create('Ext.Window',{ id : 'examplewin', title : 'tabs sample', layout : 'fit', width : 350, height : 300, draggable : false, resizable : false, plain : true, frame : false, shadow : false, items : [exTabs] }).show();
You can check the working sample of the above code by clicking the following link:
http://jsfiddle.net/kVbra/23/
1.After opening the above link, you can find the result in the lower right corner.
2. According to your question, one toolbar is created, and it is used on two tabs with the same button.
3. If you click on the button, it will receive the current tab identifier, and it will display a different result, based on which tab is activated.