Update multiple iframes based on id variable with one button

I have a php page with multiple iframes on the page.

these iframes contain a button if you want. When someone clicks on the "button" im shooting javascript to refresh another frame on the page with id = xxx, this works fine. the problem is that I want to be able to update multiple frames on a page on which they all have the same ID value, so how can this be done.

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

This works on a single iframe (I know that you cannot have multiple identifiers the same on the same document.) The idea is that you want to do something like this.

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

Sorry for the messy example, ive woke up far to long. :)

+4
source share
5 answers

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

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

Then I was able to use the code below to get all iframes with the same name and loop through them, updating 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 the help, hope this helps someone too.!

0
source

Just assign different identifiers and call

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

several times, each time for every iFrame you want to reload.

+3
source

You have two options: either iterate over all id, reloading them as necessary ...

Or, if you reload ALL frames, you can use this:

 for(var i=0;i<window.frames.length;i++){ window.frames[i].location.reload(); } 
+2
source
 /* 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' ); 
+1
source

This is not php, you just need javascript Look at this, I think this is what you need

How to update 2 frames with one link / button using html / js

0
source

All Articles