Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created October 27, 2010 19:06
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jashkenas/649724 to your computer and use it in GitHub Desktop.
Save jashkenas/649724 to your computer and use it in GitHub Desktop.
Handy Bookmarklet to recursively reload all CSS stylesheets for each frame in the page.
(function(){function f(b){b=b||window;for(var g=b.document.getElementsByTagName("link"),a=0,d=g.length;a<d;a++){var e=g[a],c=e.href;if(c&&/stylesheet/i.test(e.rel)){c=c.replace(/(&|%5C?)forceReload=\d+/,"");var h="forceReload="+(new Date).valueOf();e.href=c+(c.indexOf("?")>=0?"&":"?")+h}}a=0;for(d=b.frames.length;a<d;a++)f(b.frames[a])}f()})();
// Reload all of the CSS in each frame on the page.
function reloadCSS(win) {
win = win || window;
var links = win.document.getElementsByTagName('link');
for (var i = 0, l = links.length; i < l; i++) {
var link = links[i];
var url = link.href;
if (url && (/stylesheet/i).test(link.rel)) {
var newUrl = url.replace(/(&|%5C?)forceReload=\d+/, '');
var reloader = 'forceReload=' + (new Date().valueOf());
link.href = newUrl + (newUrl.indexOf('?') >= 0 ? '&' : '?') + reloader;
}
}
for (var i = 0, l = win.frames.length; i < l; i++) {
reloadCSS(win.frames[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment