March 19, 2012

Is there a way to check whether the html is loaded on Iframe

Question by AmGates

My problem is that I have two html files for example say 1.html and 2.html. The contents of the files are
It consists of the Iframe. The source of the Iframe is 2.html.
It is a sample html page.

My question is that I want to check whether the 2.html is loaded on an Iframe or loaded on a separate browser directly without putting it inside an Iframe. The checking has to be done from 2.html only.

Any suggestions friends.
Thanks in advance.

Answer by Sepehr

when loaded in iframe the window.parent points to the parent window, however when loaded in a separate window window.parent points to window itself:

var loadinInIframe = window.parent != window;

Answer by Starx

Bind a function inside the iframe’s onload event and set a loaded variable on the parent page

On the iframe

window.onload = function() {
   parent.iframeLoaded = true;

On the parent page, just declare the variable to hold the value

var iframeLoaded = false;

Now you can check this var when you need from the parent page like

if(iframeLoaded) {
    // Do something

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!