my baby does the same, i have read many different opinions... some say it may be because they see their reflection, and try to attack it... others say that it could be because they can see through the glass but can not get through, thus causing confusion, so they try to find a spot in the glass they can go through... others say it may be because they want out for a bit... and some have said it is them trying to get your attention.
so many reasons i know... i hope this helped...