开发者

Send url to iframe via jQuery

开发者 https://www.devze.com 2023-04-05 13:02 出处:网络
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:

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?


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


$(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);


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

You probably want a better selector.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消