4

The following code snippet will create new document object with the HTML code. By referencing the following statement, I should get the array of attached stylesheets, but I'm getting ZERO results.

doc.styleSheets

But the similar statement works fine for the current document like

document.styleSheets.

Help me to find what's I'm doing wrong.

var doc = document.implementation.createHTMLDocument(title);
doc.documentElement.innerHTML = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title</title>
    <link rel="stylesheet" href="http://localhost/style.css" type="text/css" />
  </head>
  <body>
        Hello world!
  </body>
</html>';

var sheets = doc.styleSheets; // it gives ZERO results
Raghava Kotekar
  • 471
  • 5
  • 8
  • 1
    Find out that, resources which are associated with the new document aren't loaded till it get added to the DOM. Is their any way except using iframe method to achieve this? – Raghava Kotekar Jan 19 '12 at 00:48

1 Answers1

0

Hmmm...

Are you using jQuery (or some similar framework) by any chance? If so, you could try waiting until the DOMREADY event fires, then grab your array of stylesheets.

Take a look @ this post for more info.

Community
  • 1
  • 1
Bob FiveThousand
  • 139
  • 1
  • 1
  • 8