I want to be able to change the CSS used in an iframe from a link.
My iframe does not have a name, only an id.
My code below does NOT work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<script type="text/javascript">
function addEditorCSS (child,css) {
var ifr = getElementById(child);
var headID = ifr.document.getElementsByTagName("head")[0];
var cssNode = ifr.document.createElement("link");
cssNode.type = "text/css";
cssNode.rel = "stylesheet";
cssNode.href = css;
cssNode.media = "screen";
headID.appendChild(cssNode);
}
</script>
</head>
<body>
<h1>Hello World</h1>
<iframe src="2.html" id="elm1_ifr"></iframe>
<hr />
<a href="javascript:('elm1_ifr','http://fds2432.googlepages.com/red.css')">Change CSS</a>
</body>
</html>
Open in new window
Note I change ID to NAME and fixed the href of the clicked link
Open in new window