Advertisement
rAthus

Récupérer toutes les feuilles de styles CSS d'une page en JS

Jul 16th, 2015
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var css = [];
  2. for (var i=0; i<document.styleSheets.length; i++)
  3. {
  4.     var sheet = document.styleSheets[i];
  5.     var rules = ('cssRules' in sheet)? sheet.cssRules : sheet.rules;
  6.     if (rules)
  7.     {
  8.         css.push('\n/* Stylesheet : '+(sheet.href||'[inline styles]')+' */');
  9.         for (var j=0; j<rules.length; j++)
  10.         {
  11.             var rule = rules[j];
  12.             if ('cssText' in rule)
  13.                 css.push(rule.cssText);
  14.             else
  15.                 css.push(rule.selectorText+' {\n'+rule.style.cssText+'\n}\n');
  16.         }
  17.     }
  18. }
  19. var cssInline = css.join('\n')+'\n';
  20. cssInline;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement