The following code tries to injuect some code into an iFrame (on the same server as the page). I am getting a ReferenceError: chunks is not defined error. Can somebody help me figure out why please? I’ve been baning my head on this one for a day now.
<iframe id="preview-iframe"></iframe>
<script language="JavaScript" type="text/javascript">
var chunks;
chunks += "<span class=\"bold";
chunks += "\">Hello World!</";
chunks += "span>";
document.getElementById("preview-iframe").src="javascript:void(document.write(chunks))";
</script>
You need to concatanate
'" + chunks + "'so that it is not interpreted literally. Also,iframeis a reserved word so I renamed theidon the frame.🙂