Link to home
Start Free TrialLog in
Avatar of mrotstein
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&region=y

Is this even possible?

If so, can someone provide some example code?
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

when you click on a link call this javascript

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
try this if you are using ASP

<iframe src="http://yahoo.com?<%=Request.QueryString()%>"></iframe>
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial