Use proper window object for iframe in enter/leave

Fixes #788.
Merge pull request #803 from spicyj/gh-788

Use proper window object for iframe in enter/leave