Specifying content of an iframe instead of the src attribute to a page

后端 未结 4 580
灰色年华
灰色年华 2020-11-29 00:06

I\'m currently working on a form which includes some file inputs to upload pictures. There is an onchange() event for those inputs that submits the pictures to

4条回答
  •  甜味超标
    2020-11-29 00:46

    You can use data: URL in the src:

    var html = 'Hello from SO';
    var iframe = document.querySelector('iframe');
    iframe.src = 'data:text/html,' + encodeURIComponent(html);

    Difference between srcdoc=“…” and src=“data:text/html,…” in an iframe.

    Convert HTML to data:text/html link using JavaScript.

提交回复
热议问题