PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

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

 April 15, 2022     iframe, php, smarty     No comments   

Issue

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

As shown in below picture I am using iframe inside div#email_content to show exact preview of email content. I am trying to use srcdoc 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.

Thanks!

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

enter image description here


Solution

You need to use htmlentities method in php

<?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

https://jsfiddle.net/zpx8qw1b/1/



Answered By - Tarun Lalwani
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing