mrotstein
asked on
Pass Query String from IFrame into Form Fields
I have an Iframe embedded in my web page. Inside the Iframe is a remote website with hyperlinks. When I click on the link in the Iframe I would like to copy the query string parameters to form fields on my parent page.
There are 2 parameters I need to copy to my form fields, layer and region. The links look like this: remotepage.html?layer=x&re gion=y
Is this even possible?
If so, can someone provide some example code?
There are 2 parameters I need to copy to my form fields, layer and region. The links look like this: remotepage.html?layer=x&re
Is this even possible?
If so, can someone provide some example code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function fetchValues( obj )
{
var link = obj.href;
var re = new RegExp("?", "g");
var myArray = link.split(re); \\seperating out param and URL
re = new RegExp("&", "g");
myArray = myArray[1].split(re); \\now you will get the key value pair
\\loop through the key-values and put those values in the form of the document.
\\open the new link
\\either in a seperate pop up
window.open(link);
\\or in the same screen
locatiion.href = link;
}
let me know if this was helpful