Krishanu Dey
Krishanu Dey

Reputation: 6406

Is it possible to change the source of an iframe without page postback?

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

Answers (3)

ShahidAliK
ShahidAliK

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

Jashwant
Jashwant

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

Zafer
Zafer

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

Related Questions