最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - refresh multiple iframes based on a variable "id" from one button - Stack Overflow

programmeradmin2浏览0评论

I have a php page that has multiple iframes on the page.

these iframes contain a button if you will. When someone clicks on the "button" im firing javascript to refresh another frame on the page with id=xxx this works fine. the problem is i want to be able to refresh multiple frames on the page they all cant have the same ID value so How could this be done.

<iframe id="12345"></iframe>
<iframe id="12345"></iframe>
<iframe id="12345"></iframe>

This works on a single iframe (i know you cant have multiple ids the same on one document.) The idea is want to do something like this.

parent.document.getElementById('12345').contentWindow.location.reload();

Sorry for the sloppy example, ive been awake far to long. :)

I have a php page that has multiple iframes on the page.

these iframes contain a button if you will. When someone clicks on the "button" im firing javascript to refresh another frame on the page with id=xxx this works fine. the problem is i want to be able to refresh multiple frames on the page they all cant have the same ID value so How could this be done.

<iframe id="12345"></iframe>
<iframe id="12345"></iframe>
<iframe id="12345"></iframe>

This works on a single iframe (i know you cant have multiple ids the same on one document.) The idea is want to do something like this.

parent.document.getElementById('12345').contentWindow.location.reload();

Sorry for the sloppy example, ive been awake far to long. :)

Share Improve this question asked Apr 28, 2011 at 22:10 Neil EckerNeil Ecker 552 silver badges6 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Just assign different ids and call

parent.document.getElementById(customId).contentWindow.location.reload();

multiple times, once each for every iFrame you want to reload.

You have two choices, either iterate over all the id's reloading each as needed...

Or if you are reloading ALL frames, you can use this:

for(var i=0;i<window.frames.length;i++){
  window.frames[i].location.reload();
}
/* include in parent */
function reloadIframes( ) {
    var i = argument.length;
    while ( i-- ) {
        document.getElementById( arguments[i] ).contentWindow.location.reload()
    }
}
/* In an iframe (probably in the onclick of your button) */
parent.reloadIframes( 'id1', 'id2' );

This is what I ended up using at it works great! I made the iframe as follows:

<iframe name="ifwXXXX"></iframe>

Then I was able to use the below code to get all the iframes that had the same name and loop through them refreshing each.

function refreshwant(ifid,lid){
    parent.document.getElementById('pfid'+lid+'').contentWindow.location.reload();
    var x = parent.document.getElementsByName('ifw'+ifid+'');
for(var i = 0; i < x.length; i++)
{
    x[i].contentWindow.location.reload();    
}
}

Thanks for all the help hope this can help someone as well.!

发布评论

评论列表(0)

  1. 暂无评论