How to pass URL parameters to a form in an iframe

Version 4
    This solution will ONLY work with Forms 1.0.

    Issue:

    Some customers put Landing Pages in an iFrame on their public website. In this case, URL parameters on the parent page are not passed down to the form.

     

    Solution:

    Using JavaScript, you can pull the URL from the parent page.

     

    Please ensure that you have access to an experienced JavaScript developer. Marketo Technical Support is not set up to assist with troubleshooting JavaScript.

    Place Javascript on your Form Page

     

    You can use Custom HTML or just put the following script in the template of the page that has the form on it.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <!-- Keep your jQuery up to date --> 

     

    <script> 

     

    $(function(){ var url = (window.location != window.parent.location) ? document.referrer: document.location;     var sourceParam = getUrlVars(url)["source"]; $("#LeadSource").val(sourceParam);
    }) 

     

    function getUrlVars(url) { var vars = [], hash; var hashes = url.slice(url.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1];

     

       }

     

       return vars;

     

    </script>

    You can repeat the lines in yellow if you have multiple parameters and form fields.

    That's it! Give it a try and make sure to test!