0

I've got a page with several iframes that are added by the end user via a cms. I need to append a query string (exactly the same to all iframes) to the end of the iframe source and am stuck on how to proceed.

My current code is here where .frame-wrap is a container around all iframes:

$(document).ready(function() {

    var hideLinkHeader = '?hideLink=true&hideHeader=true';
    var url = cannot figure out how to set this for each iframe

    $('.frame-wrap').find('iframe').attr('src', url + hideLinkHeader);

});

Any help is greatly appreciated.

2
  • What is url supposed to be? The original source? Commented Mar 17, 2015 at 22:04
  • @Frayt yes the original url does not change (it's different for each iframe). I need to append the query string to each one. Commented Mar 17, 2015 at 22:08

1 Answer 1

2

This should work if I'm understanding your issue correctly

$(document).ready(function() {

var hideLinkHeader = '?hideLink=true&hideHeader=true';

//Loop through every iframe in .frame-wrap
$.each($('.frame-wrap').find('iframe'), function(index, i)
{
    //set url equal to this iteration's iframe's src
    var url = $(i).attr('src');

   //set this iteration's iframe's src equal to url plus the hideLinkHeader global variable
   $(i).attr('src', url + hideLinkHeader);

});
});

Working JSFiddle: http://jsfiddle.net/srmzuheb/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.