Prevent Apple's Safari Browser from Caching an iFrames Source or URL

Safari Caching Problem

Boy, I don't know how long this one has been a thorn in my side, but if you have ever tried dynamically creating or changing the content of an iFrame and you use Apple's Safari browser, then I'm sure you have run into this issue. For what ever reason, Safari caches the source (url) of an iFrame and whenever you try to change it's content, it wants to use the old data.

Well, not anymore. I came across a great little trick tonight and I though I would share. All you have to do is change the ID of the iFrame and Safari will update it with no problems. So if you're creating iFrames on the fly, just use this little JavaScript snippet:

iFrame.id = "IF_" + new Date().getTime(); // prevent Safari from using old data.

This can easily be modified for other languages. And if needed, you can update the SRC and then change the ID back to another name. (Useful if your using a custom CSS style for the element).

Hope this saves you a headache!

2 responses to "Prevent Apple's Safari Browser from Caching an iFrames Source or URL"

Jamie McDaniel
Thanks for posting this solution.
Bartosz
Thanks for sharing! :)

Have something to say? Leave a comment!

You don't have to be registered to leave a comment. Unregistered user's comments will be approved before going live.




You are currently posting as an unregistered user.
This means that your comment will be reviewed prior to going live. If you are a registered user, please . New user? No problem, register for an account, it's FREE! Benefits include, posting instantly, screen name protection, collaboration recognition, subscribe to article updates, and so much more!