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.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.