computed-style-cross-window.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <!DOCTYPE HTML>
  2. <html class="reftest-wait">
  3. <title>getComputedStyle across windows</title>
  4. <style>
  5. p { color: blue }
  6. div { margin: 1em 0 }
  7. </style>
  8. <script>
  9. var gRunCount = 2;
  10. function run() {
  11. if (--gRunCount != 0)
  12. return;
  13. var i = document.getElementById("i");
  14. var pout = document.getElementById("out");
  15. var poutnone = document.getElementById("outnone");
  16. var poutdet = document.createElement("p");
  17. var pin = i.contentDocument.getElementsByTagName("p")[0];
  18. var pinnone = i.contentDocument.getElementsByTagName("p")[1];
  19. var pindet = i.contentDocument.createElement("p");
  20. document.getElementById("res1").style.color =
  21. window.getComputedStyle(pin, "").color;
  22. document.getElementById("res2").style.color =
  23. i.contentWindow.getComputedStyle(pout, "").color;
  24. document.getElementById("res3").style.color =
  25. window.getComputedStyle(pinnone, "").color;
  26. document.getElementById("res4").style.color =
  27. i.contentWindow.getComputedStyle(poutnone, "").color;
  28. document.getElementById("res5").style.color =
  29. window.getComputedStyle(pindet, "").color;
  30. document.getElementById("res6").style.color =
  31. i.contentWindow.getComputedStyle(poutdet, "").color;
  32. document.documentElement.removeAttribute("class");
  33. }
  34. </script>
  35. <body onload="run()">
  36. <p id="out">This is a paragraph outside the iframe.</p>
  37. <div style="display:none"><p id="outnone">This is a paragraph outside the iframe.</p></div>
  38. <iframe id="i" src="computed-style-cross-window-inner.html" onload="run()"></iframe>
  39. <div id="res1">This paragraph is the color that
  40. outerWindow.getComputedStyle says the paragraph inside the iframe
  41. is.</div>
  42. <div id="res2">This paragraph is the color that
  43. iframeWindow.getComputedStyle says the paragraph outside the iframe
  44. is.</div>
  45. <div id="res3">This paragraph is the color that
  46. outerWindow.getComputedStyle says the display:none paragraph inside the
  47. iframe is.</div>
  48. <div id="res4">This paragraph is the color that
  49. iframeWindow.getComputedStyle says the display:none paragraph outside
  50. the iframe is.</div>
  51. <div id="res5">This paragraph is the color that
  52. outerWindow.getComputedStyle says the detached paragraph inside the
  53. iframe is.</div>
  54. <div id="res6">This paragraph is the color that
  55. iframeWindow.getComputedStyle says the detached paragraph outside
  56. the iframe is.</div>