Proper glue for sticking foam on window glass? Strong enough, removable, and without gap
Small dabs of clear silicone caulk. You'll have to secure the foam while the silicone cures (maybe 4 hours), but it'll hold very well and will be a breeze to remove and clean up. You could use masking tape or lean a broom against it. Start with pea-sized dabs, and leave them round until the foam presses into them. Keep them away from the window frame for easier removal.
Double-sided foam tape. This would be fast and easy, but it would leave a small gap against the glass. This just means that you'll need to seal the foam well at the edges. Rope caulk could help with that. A few squares around the perimeter should do nicely, or you could seal the entire edge.