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
1.html
It consists of the Iframe. The source of the Iframe is 2.html.
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
}