Share On Twitter Facebook Google+ LinkedIn Pinterest Tumblr Reddit
Question

Javascript iframe dom

Tags: dom iframe javascript
Date:
Status:Resolved
Question Id:21

Hello friends,

html codes and css codes can now be written in the content adding section on my site

However, a css code can change the page layout or change things with the size and width settings, and I said, let's write the codes that the user wrote in this iframe, and I said, let's get an iframe.

var f = document.createElement(“iframe”);
f.id = “s”;
f.contentDocument.body.innerHTML = "html code;

it gives an error here too

Uncaught TypeError: Cannot read property 'body' of undefined

so how can i do that

Answer
Date:
Correct:No

You created div, not an iframe. The contentDocument is undefined.

Answer
Date:
Correct:Yes

I actually made a problem while writing here, not in the code, but anyway I solved it in another way.

This is the code if someone else sees it

var btn = document.createElement("iframe");

        var html = "html code";

        btn.src = 'data:text/html;charset=utf-8,' + encodeURI(html); document.body.appendChild(btn);

Your Answer

Review Your Answer