Friday, 18 September 2015

JavaScript to fetch CSS from WebPage

CSS Solved a Big Problem
HTML was NEVER intended to contain tags for formatting a document.
HTML was intended to define the content of a document, like:

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process.

In HTML 4.0, all formatting could (and should!) be removed from the HTML document, and stored in a separate CSS file.

Ex –

<!DOCTYPE html>
<html>
<head>
<style>
p {
    text-align: center;
    color: red;
}
</style>
</head>
<body>

<p>Every paragraph will be affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>

</body>
</html>

java script to fetch css  

var elems = document.getElementsByTagName('*');
var source = [];
var css = returnCSS(elems);
function returnCSS(elems){
for(var i=0; i<elems.length ; i++){
      //console.log(document.defaultView.getComputedStyle(elems[i],null));
      source.push(document.defaultView.getComputedStyle(elems[i],null));
      }
return source;
}console.log(css);







No comments:

Post a Comment