Gmail – Why is Gmail in an iFrame

gmailhtmliframe

I would like for someone to explain the reason that Google's Gmail is placed inside of an iFrame HTML element instead of simply placing the code in the document itself.

Best Answer

According to the Gmail blog, an iFrame is used to host the code which handles gmail so that messages opened in new windows can be used without having to reload resources, and can persist even if the parent window is closed. See this blog post for some more details on how it works.

For the technically curious among you, our friends on the Chrome team made it possible to transfer the code that runs Gmail from one window to another as the window closes. When the window that hosts the code fires an unload event, we move the iframe with the code to a surviving window. Everything continues to run, including timers and outstanding requests.