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
2010-02-10 22:45:30
+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
2010-02-10 22:46:50
Better yet, `iframe.src = "testpage.html?reload="+(new Date()).getTime();` Because you COULD get the same random number back ;)
Jacob
2010-02-10 23:05:32
@Jacob very good point.
Pekka
2010-02-10 23:08:46
@Jacob I took the liberty of adding your code to my answer.
Pekka
2010-02-10 23:09:30
what do i do with this code...
acewundabar
2010-02-10 23:11:34
@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
2010-02-10 23:15:46
@acewundabar you can edit your question and add the information, by the way.
Pekka
2010-02-10 23:23:18
<iframe src="path.html"></iframe>
acewundabar
2010-02-10 23:30:53
@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
2010-02-10 23:31:43
I want it to reload everytime the page loads? I don't understand... I want to use your code.
acewundabar
2010-02-10 23:33:09
@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
2010-02-10 23:37:44