Enumerate @font-face URLs using Javascript and regex - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Enumerate @font-face URLs using Javascript and regex

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <link rel="stylesheet" href="test.css"> 
   </head> 
   <body> 
      <h1>Hello</h1> 
      <h2>Hello</h2> 
      <script type="text/javascript">
var pattern=/url\(.*?\)/g;/*from  w  w w.  j  a v a  2  s. c o m*/
for (var i=0;i<document.styleSheets[0].cssRules.length;i++)
{
    var urls=document.styleSheets[0].cssRules[i].cssText.match(pattern);
    if (urls)
    {
        for (var j=0;j<urls.length;j++)
        {
            console.log(urls[j]);
        }
    }
}

      </script>  
   </body>
</html>

Related Tutorials