DonJuma
DonJuma

Reputation: 2094

Using ajax to change iframe

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

Upvotes: 2

Views: 7339

Answers (2)

Fosco
Fosco

Reputation: 38516

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'); 
});

Upvotes: 2

ceejayoz
ceejayoz

Reputation: 180004

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

Upvotes: 2

Related Questions