Passing URL parameters to iframe

I would like to grab the parameters from a page that contains an iframe, and append the parameters to the src of the iframe.




<iframe id="myiframe" name="myiframe" src="" frameborder="0"
width="100%" height="800"></iframe>

Here’s one of the many things I’ve tried, which I thought would work in theory, but I had no luck with it:

<script language="javascript">
$(function() {

    var loc = window.location.toString(),
    params = loc.split('?')[1],
    params2 = loc.split('&')[2],
    iframe = $('#myiframe');


    iframe.src = iframe.src + '?' + params + '&' + params2;


if your using jQuery you might want to strip down your code up:

$(function() {
    var search =;
    $("#myiframe").attr("src", $("#myiframe").attr("src")+search);

Use; as it will snip off the hash tag at the end of the url and is a lot faster as it is native code.

Then use jQuery selectors to find and replace the attribute of src on the iframe, with it’s current src plus the search acquired from this page.

Hope this helps.

You could append the querystring to the source of the iFrame

<script language="javascript">
    var iframe = document.getElementById('myiframe');
        iframe.src = iframe.src +;

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   why does javascript getMonth count from 0 and getDate count from 1?

Similar Posts