Skip to content

Instantly share code, notes, and snippets.

@mavenlink
Created February 15, 2012 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mavenlink/1838523 to your computer and use it in GitHub Desktop.
Save mavenlink/1838523 to your computer and use it in GitHub Desktop.
Fix Chrome background refresh bug
function refreshBackgrounds(selector) {
// Chrome shim to fix http://groups.google.com/a/chromium.org/group/chromium-bugs/browse_thread/thread/1b6a86d6d4cb8b04/739e937fa945a921
// Remove this once Chrome fixes its bug.
if (/chrome/.test(navigator.userAgent.toLowerCase())) {
$(selector).each(function() {
var $this = $(this);
if ($this.css("background-image")) {
var oldBackgroundImage = $this.css("background-image");
setTimeout(function() {
$this.css("background-image", oldBackgroundImage);
}, 1);
}
});
}
}
// You'll need to call this every time the event occurs that exposes the bug, such as changing tab divs.
refreshBackgrounds(".something-with-a-background-image");
refreshBackgrounds("*"); // but it'll be slow!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment