In the above code, there is a statement var adtabid = 1;. It works when you add the AdSense code to the second tab (the tab id starts from 0). If you add the AdSense to a different tab, make sure to change the number accordingly.

The code will initialise the AdSense when the second tab is clicked and switched on.