Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change src of iframe and then reload the iframe

I managed to change an iframe's src with javascript

var path='images/tattoo/fullsize/';
var h=$('#borderlessFrame').height();
var bigFrame=$('#borderlessFrame');
function loadGallery(num)
{
    bigFrame=$('#borderlessFrame');
    var galPath=path + num;             // path to the image
    h=$('#borderlessFrame').height();
    var source=bigFrame.attr('src');
    source='i load some address here';
}

But for now i see the old content of the iframe , is there a way to reload the iframe ( only iframe not the whole page) The thing i am trying to achieve is a simple gallery , thumb pictures on the bottom and a large picture on the top ( iframe ). On click on any of the thumbs , i change the content of the iframe without reloading the actual page.

Keep in mind that i am new to html/javascript/jquery. So basically i need a way(function?) to reload the iframe.

like image 581
Jordashiro Avatar asked Jan 24 '12 15:01

Jordashiro


2 Answers

To set attribute, you need to call .attr( attributeName, value )

Try this:

var source='i load some address here';
bigFrame.attr('src', source);

Reference:

jQuery .attr()

like image 106
Sarim Avatar answered Nov 08 '22 19:11

Sarim


jQuery has the load method, which is useable like so (assuming borderlessFrame is the id of the <iframe>):

var iFrame = $('#borderlessFrame');
iFrame.load('http://theurltoload.com')

However, iframes seem like an unnecessary approach for your requirements, consider looking into CSS and the jQuery DOM manipulation methods a little more.

like image 41
Rich O'Kelly Avatar answered Nov 08 '22 20:11

Rich O'Kelly