How to check iframes are loaded completely in browser

Many times we use the iframes in site for loading the some extra content. Some time we need trigger events when iframes are loaded completely in browser. Here we check iframes loaded.

iframes are loaded completely in browser

In webpage loading Iframe and controlling site UI is very important.

This script is able to check local or cross domain iframe is loaded or not.

I tested following script with various browsers and OS. So there is no cross browser issue.

[viral-lock message=”Code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


var iframe = document.createElement("iframe");
iframe.src = "https://purabtech.in/";
if (navigator.userAgent.indexOf("MSIE") > -1 && !window.opera){
iframe.onreadystatechange = function(){
if (iframe.readyState == "complete"){

alert("Iframe is now loaded.");
}
};
} else {
iframe.onload = function(){

alert("Iframe is now loaded.");
};
}


[/viral-lock]

 

iframes are loaded completely in browser
iframes are loaded completely in browser

Have fun!

send a variable value from an Iframe back to its parent

We have javascript code for how to send a variable value from an Iframe back to its parent? If you want fetch the variable value or send variable to parent page.

how to send a variable value from an Iframe back to its parent?

Use following code:
In Parent page use this copy paste folliwing javascript.


function showValue(testval)
{
alert(testval);
//here in parent page you call any other function as per your need.
}

In Iframe page use following code. In Iframe page use this copy paste folliwing javascript.


// Calls the function showValue in the parent object
// and passes the value of 't' to it
function passToParent(val)
{
var testval;
if ( (testval = window.parent) && (testval = testval.showValue) && ('function' == typeof testval || 'object' == typeof testval) ){
testval(val);
}
}

This will solve your problem.