I have the HTML for a website saved in a JavaScript string and I want to display it within an iframe. How can I insert this HTML string into the iframe and make the website appear? I have attempted to use this.src = HTML_STR; this.innerHTML = HTML_STR; but they do not display the HTML_STR.
I realize that this may seem unnecessary because instead of storing the website's HTML in a string, I could simply set the iframe's source to the website and display it that way.
HOWEVER, the reason for doing this is because it's a website updater. I want to retrieve the HTML of the website I am updating, convert all elements with the class "updatable" to textareas (so they can be updated), and then display that HTML in the iframe.
Another reason for using an iframe instead of just inserting the HTML into a div is because each website imports a .css stylesheet. I do not want their CSS to interfere with my updater website's CSS or vice versa. By displaying each website in an iframe, their CSS will not affect each other.
For instance, if updater.css contains the following, it will impact all the p elements in the other websites' HTML:
p { background-color: red; width: 50%; }
Therefore, is there a way to insert my own HTML into an iframe? Or is there another method to achieve what I am attempting to do.