OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <style type="text/css" media="screen"> | 3 <style type="text/css" media="screen"> |
4 body { background:green; } | 4 body { background:green; } |
5 </style> | 5 </style> |
6 <script> | 6 <script> |
7 var styleElements = []; | 7 var styleElements = []; |
8 function handleMessage(event) | 8 function handleMessage(event) |
9 { | 9 { |
10 function addStyleSheet(styleContent) | 10 function addStyleSheet(styleContent) |
11 { | 11 { |
12 var styleElement = document.createElement("style"); | 12 var styleElement = document.createElement("style"); |
13 styleElement.textContent = styleContent; | 13 styleElement.textContent = styleContent; |
14 document.head.appendChild(styleElement); | 14 document.head.appendChild(styleElement); |
15 styleElements.push(styleElement); | 15 styleElements.push(styleElement); |
16 } | 16 } |
17 | 17 |
18 switch (event.data) { | 18 switch (event.data) { |
19 case "addStyleSheets": | 19 case "addStyleSheets": |
20 addStyleSheet("body { background-color: yellow; }"); | 20 addStyleSheet("body { background-color: yellow; }"); |
21 addStyleSheet("body { background-color: yellow; }\n/*@ sourceURL=stylesh
eet-added-in-iframe.css */"); | 21 addStyleSheet("body { background-color: yellow; }\n/*# sourceURL=stylesh
eet-added-in-iframe.css */"); |
22 break; | 22 break; |
23 case "removeStyleSheets": | 23 case "removeStyleSheets": |
24 for (var i = 0; i < styleElements.length; ++i) | 24 for (var i = 0; i < styleElements.length; ++i) |
25 document.head.removeChild(styleElements[i]); | 25 document.head.removeChild(styleElements[i]); |
26 styleElements = []; | 26 styleElements = []; |
27 break; | 27 break; |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 window.addEventListener("message", handleMessage, false); | 31 window.addEventListener("message", handleMessage, false); |
32 </script> | 32 </script> |
33 </head> | 33 </head> |
34 | 34 |
35 <body> | 35 <body> |
36 </body> | 36 </body> |
37 | 37 |
38 </html> | 38 </html> |
OLD | NEW |