Created
October 27, 2010 19:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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()})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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