Birds tap on and attack windows because they see their own reflections in the windows but do not recognize that they see their own image. Because many species of birds are territorial, they consider the bird that they see to be an invader or trespasser and attack. This behavior often occurs during mating season and can be dangerous for the birds.
As a result of not recognizing their own image, birds often crash into windows when trying to attack perceived trespassers. According to the Monmouth County Audubon Society, 97 million birds die every year in the United States from attacking windows. Even those birds that don't die can become exhausted from repeated attacks on a window, making the birds more vulnerable to predators.
Steps to take to keep birds from tapping on or attacking windows include closing curtains or pulling down shades; doing so mitigates the reflection from the outside. Turning on lights as night approaches removes the bird's reflection. Placing a non-reflective screen on the outside of the glass also eliminates the reflection and dissuades the birds, as does adding decals or strips of tape or paper to the window. Sometimes taking these precautions only during nesting or migrating season is sufficient to keep birds from tapping or attacking windows.