Pass Query String from IFrame into Form Fields

Posted on 2010-01-07
Last Modified: 2012-05-08
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?
Question by:mrotstein
    LVL 40

    Expert Comment

    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;

       \\or in the same screen
       locatiion.href = link;

    let me know if this was helpful
    LVL 22

    Expert Comment

    try this if you are using ASP

    <iframe src="<%=Request.QueryString()%>"></iframe>
    LVL 75

    Accepted Solution

    1. short answer: Not possible
    2. longer version: have a proxy on your site read and present the content of the foreign site in the iframe with added onclick event handlers to pass data to the parent window which is now possible since both parent and iframe content is from same server, protocol and portnumber.
    3. If you have access to the iframe content, you MAY be able to add the stuff you want to and poll that from the parent.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now