开发者

Using ajax to change iframe

开发者 https://www.devze.com 2023-01-23 20:24 出处:网络
Is it possible to change the URL of an iframe without leaving the page. I.e. Ajax If so how can this be done.

Is it possible to change the URL of an iframe without leaving the page. I.e. Ajax If so how can this be done. Thanks so开发者_如何学编程 much


Yes, using just javascript (I used jQuery)..

Example is here:

http://jsfiddle.net/pYG2z/

HTML:
<iframe id="googframe" src="http://www.google.com"></iframe>
<input type=button id="changeframe" value="Change">


JS:
$('#changeframe').click(function() {
  $('#googframe').attr('src','http://www.msn.com'); 
});


var iframe = document.getElementById('your_iframe');
iframe.src = 'http://example.com/';
0

精彩评论

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