1

I want to send a url to an iframe using an ajax call, but I'm not sure if this is possible.

Here's what I have so far:

<script>
$(document).ready(function() {
  $('.clickme').click(function() {
      var id = $(this).attr(id);
      // Need to send the URL below to the iframe
      // http://www.example.com/?list_id=id    
  });
});
</script>

<iframe name="get_data"></iframe>

<div class="clickme" id="3453">Click Here</div>

Any suggestions?

0

4 Answers 4

2
$("iframe[name='get_data']").prop("src", "http://www.example.com/?list_id=" + id);
Sign up to request clarification or add additional context in comments.

Comments

1
$(document).ready(function() {
  $('.clickme').click(function() {
      var id = $(this).attr(id);
      $('iframe[name="get_data"]').attr('src', 'http://www.example.com/?list_id=' + id);

  });
});

if you are using jquery 1.6 or higher use prop (as stated by Andrew Whitaker )

$("iframe[name='get_data']").prop("src", "http://www.example.com/?list_id=" + id);

Comments

0
$('iframe').attr('src', url);

You probably want a better selector.

Comments

0

You should be able to just get a handle on the iframe and set its src attribute:

$('iframe[name="get_data"]').attr('src', 'http://www.example.com/?list_id=' + id);

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.