简体   繁体   English

更改iframe的src,然后重新加载iframe

[英]change src of iframe and then reload the iframe

I managed to change an iframe's src with javascript 我设法用javascript更改了iframe的src

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 ). 但是现在我看到了iframe的旧内容,有没有办法重新加载iframe(只有iframe而不是整个页面)我想要实现的是一个简单的画廊,底部的拇指图片和大图片顶部(iframe)。 On click on any of the thumbs , i change the content of the iframe without reloading the actual page. 单击任何一个拇指,我更改iframe的内容而不重新加载实际页面。

Keep in mind that i am new to html/javascript/jquery. 请记住,我是html / javascript / jquery的新手。 So basically i need a way(function?) to reload the iframe. 所以基本上我需要一种方法(函数?)来重新加载iframe。

To set attribute, you need to call .attr( attributeName, value ) 要设置属性,需要调用.attr( attributeName, value )

Try this: 试试这个:

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

Reference: 参考:

jQuery .attr() jQuery .attr()

jQuery has the load method , which is useable like so (assuming borderlessFrame is the id of the <iframe> ): jQuery有load方法 ,可以这样使用(假设borderlessFrame<iframe>的id):

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. 但是,iframe似乎是一种不必要的方法来满足您的需求,请考虑更多地考虑CSS和jQuery DOM操作方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM