How to catch the admin tab switching event in Magento 2
Since Magento 2 utilizes the standard jQuery UI Tabs Widget, you should catch the tabsactivate event to catch the admin tab switching:
1 2 3 4 5 6 7 8 9 10 11 12 |
var $tabs = $('#page_tabs'); if ($tabs.length) { /** @type HTMLDivElement */ var tabContent = $textarea.closest('.ui-tabs-panel').get(0); if (tabContent) { $tabs.bind('tabsactivate', function(event, data) { if (data.newPanel.get(0) === tabContent) { // your code here } }); } } |
$textarea.closest(‘.ui-tabs-panel’).get(0) is a tab you should handle.
data.newPanel.get(0) is the one that becomes active.