I am creating an Iframe and trying to add Html to it's body, butI constantly get an error Cannot read property body of null.
My code looks something like this:
var frameToPrint = document.createElement("IFRAME") as HTMLFrameElement;
frameToPrint.contentDocument.body.innerHTML = "";
Thank you in advance!
I found the answer. You need to append the new created frame to your body. That initializes the contentWindow and the contentDocument of the iframe.
var frameToPrint = document.createElement("iframe");
frameToPrint.setAttribute("name", "prnt");
document.body.appendChild(frameToPrint);