Just to add to the other answers - I have the RSPB bird stickers on all the windows that birds tend to visit.
Bird window stickers (come in different patterns - in my case use the butterfly ones)
There are lots of others like that also.
I did that after a bird visiting the bird feeder attached to my window flew straight through the window and killed itself in one go.
They now no longer fly into the windows at all from outside. But it also helps when they are trapped inside.
They still try to fly out through the window but only from close up not from a distance. Hop to the base of the window first, then try to get out from there - so not flying against the window from a distance.
I didn't know about the trick of putting a towel or cloak over them.
What I did last time it happened was to put a sheet of cardboard into the bottom of the window the bird was trying to escape out of - so it is opaque. It then gave up on that window and hopped to the floor. And I then opened the patio doors next to it and it found its way out reasonably quickly.
Must try this towel / coat thing though, next time it happens. Though would need to be careful not to hurt or frighten them. Tend to get frightened when I'm at least a couple of meters away (a largish room) so that might be tricky to catch it in a towel without hurting it or scaring it. Will have to see.