How To Get Variable From Parent Url Or Parent Iframe?
Solution 1:
As Eugen Rieck is trying to find out, content can only communicate through iframes when they originate from the same domain, otherwise you will run into the same origin policy.
To communicate with a document in an iframe you can use
var frame=window.document.getElementById('yourFrame');
var doc=frame.contentWindow.document;
You can then communicate with the elements of the document in the iframe.
I would include the variable that you are trying to "grab" in example.php as a hidden text input. You can do this by running a querystring:
var queryString = new Object;
var qstr = window.location.search.substring(1);
varparams = qstr.split('&')
for (var1=0; i<params.length; i++) {
var pair = params[i].split('=');
queryString[pair[0]]=pair[1];
var variable = queryString['variable'] //find the value of variable
document.write("<input style='visibility:hidden' id='variable' type='text' value='"+ variable +"'></input>");
Once that is in the iframed document, pull it back out in the parent by using:
var variable = doc.getElementById('variable').value;
and bob's your uncle.
Let me know if this helps....
----EDIT----
Alternatively, if you were to write this in a function in the parent page, to invoke it from the child page you could use:
function callParentFunction() {
parent.getVariable();
returnfalse;
}
You could run an onload to call this or something
Post a Comment for "How To Get Variable From Parent Url Or Parent Iframe?"