views:

367

answers:

2

How can I force an iframe to reload and not load from cache?

A: 
someIframe.src += "#forceReload";

Should work. or:

someIframe.src += "?fakeQuery";
Avindra Goolcharan
+1  A: 

To force it to reload every time, add a random GET parameter to its URL:

iframe.src = "testpage.html?reload="+Math.random();#

or as Jacob suggests, the current timestamp (eliminating the possibility of duplicates):

iframe.src = "testpage.html?reload="+(new Date()).getTime();
Pekka
Better yet, `iframe.src = "testpage.html?reload="+(new Date()).getTime();` Because you COULD get the same random number back ;)
Jacob
@Jacob very good point.
Pekka
@Jacob I took the liberty of adding your code to my answer.
Pekka
what do i do with this code...
acewundabar
@acewundabar If you want a more detailed explanation, you will need to show the code you currently use to embed the iframe, and maybe explain some more about your situation.
Pekka
@acewundabar you can edit your question and add the information, by the way.
Pekka
<iframe src="path.html"></iframe>
acewundabar
@acewundabar Please explain what your situation is and what you want to do. I'm not going to explain all 1500 ways of giving an iframe a new src.
Pekka
I want it to reload everytime the page loads? I don't understand... I want to use your code.
acewundabar
@acewundabar I'm sorry I can't help you with this right now, I need to leave for the day. Maybe someone else will pick up the thread. What you need to do is, you need to build a JavaScript that assigns the iframe's `src` when the document loads. This can't be done using simple HTML I'm afraid.
Pekka