<html>
<head>
<style type="text/css" media="screen">
body { background:green; }
</style>
<script>
var styleElements = [];
function handleMessage(event)
{
function addStyleSheet(styleContent)
{
var styleElement = document.createElement("style");
styleElement.textContent = styleContent;
document.head.appendChild(styleElement);
styleElements.push(styleElement);
}
switch (event.data) {
case "addStyleSheets":
addStyleSheet("body { background-color: yellow; }");
addStyleSheet("body { background-color: yellow; }\n/*# sourceURL=stylesheet-added-in-iframe.css */");
break;
case "removeStyleSheets":
for (var i = 0; i < styleElements.length; ++i)
document.head.removeChild(styleElements[i]);
styleElements = [];
break;
}
}
window.addEventListener("message", handleMessage, false);
</script>
</head>
<body>
</body>
</html>