How to encode PHP string of HTML for use as string by JavaScript function? -
i've got following code:
<iframe id="uniqueid" frameborder="0" width="100%" height="100%"></iframe> <script> var iframeobject = document.getelementbyid("uniqueid"); var iframecontent = iframeobject.contentwindow.document; iframecontent.open(); iframecontent.write("<?php echo $htmlstring ?>"); iframecontent.close(); </script>; i'm trying insert user-generated html (metadata, <html>, <head>, <body>, <script>s , all), stored string in php variable $htmlstring, #uniqueid iframe browser/client render.
i'm having hard time figuring out proper way safely escape/encode string of html use in javascript i've written.
on php side, i've tried htmlspecialchars(), htmlentities(), json_encode(), , simple str_replace()s on $htmlstring, none of them need them to. there i'm missing?
i think should save code file , loads src attribute domain.
at least jsfiddle.net uses way.
Comments
Post a Comment