Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering Javascript within a Sub Tab?

JayFogelson2
Contributor III

Wondering what the trick is, to get javascript in a custom object, to fire in a TabSet on a record?  Is there some sort of event listener to leverage?

 

Using just a simple alert, like below, the alert only triggers if you are on the sub tab and toggle between view/edit.  If you do not have the sub tab in focus, load the page, navigate to the sub tab, it does not fire.

 

<script>

    alert('hello world');

</script>

Thanks in advance!

4 REPLIES 4

Ilya_Khen
Champion III

Ilya_Khen
Champion III

ALso, if you have on the section outside of a tab:

Sys.Application.add_load(function() {})

That part of a code will be executed every time your tab is loaded.

 

Which may help you to trigger the function inside the tab.

DavidPetty
Archer Employee
Archer Employee

It's the way ASP.NET loads the tab contents that doesn't fire the script tags.

 

Using the function pageLoad({ //Code Here ]); in a custom object outside of the tab set will fire when the tabs are changed.  You'd just have to determine which tab the user is on and execute the necessary code.

 

Something like this to determine which tab to execute code on:

<script type="text/javascript">
     var fldId = 15349;
     var tabIndex = 1;

     function pageLoad() {
          var layoutId = $CM._fields[fldId].layoutId;
          var tabId = $LM._layoutItems[layoutId].tabId;
          var tabSetId = $LM._tabs[tabId].tabSetId;

          var tabStripElementId = 'master_DefaultContent_rts_ts' + tabSetId + '_t';
          tabStrip = $find(tabStripElementId);

          if (tabStrip._selectedIndex == tabIndex) {
               //Code to execute
          }
     }
</script>
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The tabIndex variable is which tab you want to execute the code on and the fldId variable is a way to get the tab set id.

 Advisory Consultant

Anonymous
Not applicable

Image result for we're not worthy