PDA

View Full Version : No Cache Iframe



sartajc
05-28-2006, 05:03 PM
I want to iframe/regularframe to an external site, but the external site is dynamic and changes alot. So how do i make an iframe or frame not cache so everytime the frame reloads itll be updated?

ddadmin
05-28-2006, 05:15 PM
Since the site inside the iframe is external, unfortunately you can't do anything to affect its cache settings. If the site was on your own server, you could, for example, use meta tags to specify the page's caching.

Twey
05-28-2006, 05:21 PM
Actually, that's not quite accurate.
If you do something like, for example:
<iframe src="http://www.example.com/thepage.html" name="aframe"></iframe>
<script type="text/javascript">
document.frames['aframe'].location.href += (document.frames['aframe'].location.href.indexOf("?") != -1 ? "?" : "&") + (new Date()).getTime();
</script>... that should break caching in all Javascript-enabled browsers.

However, it should be noted that this is a last resort only; if the external site's page changes regularly, they should have already taken server-side steps to assure that the cache is updated regularly.

sartajc
05-28-2006, 06:42 PM
Actually, that's not quite accurate.
If you do something like, for example:
<iframe src="http://www.example.com/thepage.html" name="aframe"></iframe>
<script type="text/javascript">
document.frames['aframe'].location.href += (document.frames['aframe'].location.href.indexOf("?") != -1 ? "?" : "&") + (new Date()).getTime();
</script>... that should break caching in all Javascript-enabled browsers.

However, it should be noted that this is a last resort only; if the external site's page changes regularly, they should have already taken server-side steps to assure that the cache is updated regularly.

ehhhh...it didn't work. Check it out here: http://muson.susanasjewelry.com/forum/randomhelp.html .

ddadmin
05-28-2006, 07:48 PM
Ah yes Twey, I forgot about the "random number suffix" technique. How about this sartajc:


<script type="text/javascript">
var randomnumber=Math.floor(Math.random()*100000)

document.write('
<iframe src="http://www.freedonation.com/hunger/hunger_thankyou.php3?random='+randomnumber+'" name="aframe" width="100%" height="400"></iframe>')

</script>

Twey
05-28-2006, 08:02 PM
... but that's JS-dependent. Also doesn't cater for GET variables (which are likely, since it is, to quote, a "dynamic" page).
Use my code. I made three obvious mistakes, and probably about twenty subtle ones. :)

<iframe src="http://www.freedonation.com/hunger/hunger_thankyou.php3" style="width:100%;height:400px;" name="aframe"></iframe>
<script type="text/javascript">
var location = "http://www.freedonation.com/hunger/hunger_thankyou.php3";
(document.frames || window.frames)['aframe'].location.href = location + (location.href.indexOf("?") == -1 ? "?" : "&") + (new Date()).getTime();
</script>

ddadmin
05-28-2006, 11:51 PM
Well I thought I'd just throw the OP the line to get the fish. :) You're right, your code is more flexible though.

sartajc
05-29-2006, 12:17 AM
It worked....only in firefox. Not IE7. and most of the people that visit my site uses IE (grrrrr. i wish they used firefox. its so much better).

check it out here: http://muson.susanasjewelry.com/forum/help.htm .
Look what it does in firefox, and what it does in IE. actually does something in firefox, but does nothing in IE.

i used both ddadmins and tweys code. why won't it work in IE? (of course nothing works in IE :) )

oh yeah, i dont have to use iframe. regular frame, php, or anything else will work. as long as it works.

btw, theres millions of tech forums, but this one is the best one i have encountered.

Twey
05-29-2006, 12:29 AM
For me it works in IE (v6). Firefox... what on earth?!
Ah... try this one:
<iframe src="http://www.freedonation.com/hunger/hunger_thankyou.php3" style="width:100%;height:400px;" name="aframe"></iframe>
<script type="text/javascript">
var dokoka = "http://www.freedonation.com/hunger/hunger_thankyou.php3";
(document.frames || window.frames)['aframe'].location.href = dokoka + (dokoka.href.indexOf("?") == -1 ? "?" : "&") + (new Date()).getTime();
</script>

sartajc
05-29-2006, 11:20 PM
For me it works in IE (v6). Firefox... what on earth?!
Ah... try this one:
<iframe src="http://www.freedonation.com/hunger/hunger_thankyou.php3" style="width:100%;height:400px;" name="aframe"></iframe>
<script type="text/javascript">
var dokoka = "http://www.freedonation.com/hunger/hunger_thankyou.php3";
(document.frames || window.frames)['aframe'].location.href = dokoka + (dokoka.href.indexOf("?") == -1 ? "?" : "&") + (new Date()).getTime();
</script>


Thank You! it worked in IE7! but now its not working in firefox...HOWEVER. thats not a problem. Ill just run both scripts! Thanx a lot! ill link back to this site!

check out the double iframe thingy here: http://muson.susanasjewelry.com/forum/rand.htm