0

I have a problem with iframe. I added HTML code (string - I get that code from DB) in the <body> of iframe but I can't see that code as HTML, its just a string.

document.getElementById("iframe_with_content").ready(function() {
        (document.getElementById("iframe_with_content").contentWindow.document).write("<%= post.text %>");
        (document.getElementById("iframe_with_content").contentWindow.document).close();
});

bug

Denis Lapadatovic
  • 305
  • 1
  • 9
  • 16

2 Answers2

2

Include jQuery to your page, and

var data = $('<textarea />').html("<%= post.text %>").text();
document.getElementById("iframe_with_content").ready(function() {
        (document.getElementById("iframe_with_content").contentWindow.document).write(data);
        (document.getElementById("iframe_with_content").contentWindow.document).close();
});

Explanation: your data provided by <%= post.text %> was actually html-entity-encoded. So actually you've got something like sadasds&lt;i&gt;dasd....

Ben
  • 410
  • 3
  • 11
0

This can occur because of html escaping done by ejs try and check to see whether this works:

<%- post.text %>

Refer : How to escape HTML in node.js EJS view?

WARNING: Be careful using these functions please check XSS attacks