Question: Why Do People Tap on Cans?
Answer: Tapping on the top of a carbonated beverage can (or bottle) before opening it may help prevent the drink from exploding out of the can upon opening (although it might not be sufficient!). Sparkling or carbonated beverages contain carbon dioxide gas that is dissolved in the liquid by pressurizing the contents of the can. When the can is opened, the mixture depressurizes and the carbon dioxide comes out of solution, escaping as carbon dioxide gas. If there is liquid between the gas bubble and the outside of the can, then some of the liquid may be pushed out of the can with the bubble. The pressure gradient when the can is opened is greatest near the opening and the carbon dioxide at the top of the can escapes first.
If the can has been shaken, then the pressure differential inside the can during shaking will force some of the carbon dioxide out of solution to form bubbles. Some bubbles float to the top and some stick to the sides and bottom of the can. Given sufficient time, equilibrium will be achieved and the carbon dioxide will dissolve back into the beverage. If the can is opened immediately after shaking, it is likely that the beverage will spray all over the place, since some liquid from all parts of the can will be pushed ahead of escaping gas and out the can (hey, bubbles float to the top and these bubbles are under pressure too!). When the can is tapped before opening, bubbles adhering to the sides and bottom of the can may be jarred free. Assuming the can is upright, the bubbles, being lighter than the liquid, will float to the top of the can. Then when the can is opened, the bubbles are already near the opening, so they don't push through the beverage on their way out.
Here's a little experiment to try at home: Shake up two cans of cola (or whatever is handy). Place one can right side up and the other inverted. Tap the 'top' of each can. Now turn the upside-down can over and open both cans. Did you get sprayed more by the can that was inverted when it was tapped?
In addition to tapping on the can, the risk of getting soaked is reduced if the can or bottle is opened slowly rather than quickly because then the initial pressure change is less significant, so the gas can escape less forcefully. The wider the top of the container, the better the chance to avoid an accident, since there is more volume for gas without intervening liquid. It also follows that if you shake up a can in zero-gravity, then tapping on the can won't work (although opening the can slowly will help), since the bubbles aren't going to preferentially float toward the top of the can! Maybe tapping on the can makes the problem more likely, since tapping dislodges the bubbles clinging to the can, so there is nothing slowing them down when the can is cracked. Is that why cosmonauts drink vodka instead of Coca Cola? Hmmmm...