Question

I'm working on a project which passes a variable into a iFrame with this code:

jQuery(function() {
    var search = window.location.search;
    jQuery(".iframe-wrapper").attr("src", jQuery(".iframe-wrapper").attr("src")+search);
});

But, when I pass through &section=P1 in a URL, it just gives a 404.

Source of the iFrame: example.com/page?cart=1

After going to site.com/&section=P1 the iFrame should change to example.com/page?cart=1&section=P1

Anyway to pass through the &section=P1 through the URL?

Was it helpful?

Solution

Please send your HTML as mine is working fine with the below:

  <iframe width="500" height="200" class="iframe-wrapper" src="http://www.google.com?param=1"></iframe>
    <script type="text/javascript">
     $(function() {
    var search = window.location.search;
    search = search.replace("?","&");

    $(".iframe-wrapper").attr("src", $(".iframe-wrapper").attr("src")+search);
    });
    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top