code_junkie

Changing the stylesheet of a nested page at runtime

Nov 12th, 2011
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <object name="nestedPage" data="http://abc.com/page.html" type="text/html"
  2. width="500" height="400" />
  3.  
  4. d = document.getElementsByTagName('object').namedItem('nestedPage').getContentDocument();
  5. d.styleSheets[d.styleSheets.length].href = 'whereever';
  6.  
  7. $("link [rel=stylesheet]", myFrame).attr('href', <new-url>);
  8.  
  9. function applyCSS(css) {
  10. // http://www.quirksmode.org/bugreports/archives/2006/01/IE_wont_allow_documentcreateElementstyle.html
  11. if (BrowserDetect.browser=="Safari" || BrowserDetect.browser=="Opera") { /* good for FF too */
  12. var styleNode = document.createElement("style");
  13. styleNode.setAttribute("type", "text/css");
  14. styleNode.appendChild(document.createTextNode(css));
  15. head.appendChild(styleNode);
  16. } else {
  17. var div = document.createElement("div");
  18. div.innerHTML = "<p>x</p><style>"+css+"</style>";
  19. document.body.appendChild(div.childNodes[1]);
  20. }
  21. }
  22.  
  23. var doc = iframe.document;
  24. if(iframe.contentDocument)
  25. doc = iframe.contentDocument; // For NS6
  26. else if(iframe.contentWindow)
  27. doc = iframe.contentWindow.document; // For IE5.5 and IE6
  28. // Put the content in the iframe
  29. doc.open();
  30. doc.writeln(content);
  31. doc.close();
Add Comment
Please, Sign In to add comment