Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

Why datauri in iframe should be encoded

Hi,
I have the following js :
 var contentCss = '<link href="https://cdn.ckeditor.com/4.5.6/full/contents.css" rel="stylesheet" type="text/css"/>';
    var iframeSrc= contentCss + '<body><div id="textArea" class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders">' + noteBody + '</div><body>';

    document.getElementById('iframe').src = 'data:text/html;base64,' + btoa(iframeSrc);
//    document.getElementById('iframe').srcdoc = iframeSrc;

Open in new window

There are two possible ways i can render this iframeSrc string... which is actually an html string..
One is that i encode it and use it in iframe src... other way is i directly use the whole html string in srcdoc.

Which is the preferable way ?
Also why do we need to encode data when specifying data URIs ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial