Aviator Aviator - 7 months ago 87
Smarty Question

How to set HTML code in "srcdoc" attribute of iframe?

<div id="email_content">
<iframe srcdoc="{$email_content}"></iframe>

As shown in below picture I am using iframe inside
to show exact preview of email content. I am trying to use
attribute to load email content in the iframe. Here the email content might be a plain text or HTML content designed through CkEditor. I tried using escape, htmlentities, etc. But the srcdoc attribute breaks because the attribute value contains pure HTML code and quotes.

Any work-around will be accepted.


Note: I don't want to use
attribute here.

enter image description here

Answer Source

You need to use htmlentities method in php

$str = '<a href="https://www.tarunlalwani.com">Go to tarunlalwani.com</a>';
echo htmlentities($str);

And then assign that to srcdoc. It works as shown in below JSFiddle


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download