Reputation: 6406
I just wanted to know, is it possible to change the source of an iframe without page postback? if yes, then how.
Upvotes: 1
Views: 5910
Reputation: 50
For the first load : $(document).ready(function() { var myIframe = document.getElementById('yourIFrameID');
if(myIframe != undefined || myIframe != null)
myIframe.src = "newSource";
});
AND call following setIFrameSrc() function from any place you want to.
function setIFrameSrc(newURL)
{
var myIframe = document.getElementById('yourIFrameID');
if(myIframe != undefined || myIframe != null)
myIframe.src = newURL;
}
Upvotes: 0
Reputation: 29015
If I am getting your question right, answer is no.
If you will change the source of an iframe, a new page will load in it.
If your markup is
<iframe id='myframe' src='http://www.abc.com' ></iframe>
And you do,
document.getElementById('myframe').src = 'http://www.xyz.com';
it will reload and open xyz.com.
Upvotes: 1
Reputation: 2190
Using jquery.attr() method, you can change the src parameter.
$("#myifrm").attr("src","your url here");
To see a working sample, take a look at this: http://jsfiddle.net/YCDtj/
Upvotes: 1