Use proper window object for iframe in enter/leave

Fixes #788.