Is there a way to load full HTML code without iFrame?
iFrame is not a good solution, because:
- The preview is before actually saving the content, so I cannot provide an URL for iFrame to load the page.
- It is difficult to touch the element inside iFrame. As the user will be doing minor update in another text box showing the plain HTML, I will need to update the elements inside frequently.
However, if I just insert content into an
<div> the repeated
<body>tag will crash the page.
So, is there a way I can preview the HTML without iFrame?
if you dont want to have the main app to affect the styling of the preview, you need to use iframe. have you see iframe's content window? https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/contentWindow. this might be the answer you are looking for. So basically here you try to access the DOM of your iframe. give it a try!
preview = getYourIframeDom(); code = getYourHtmlCodeHere(); preview.contentWindow.document.open("text/html","replace"); preview.contentWindow.document.write(code); preview.contentWindow.document.close();