Vai al contenuto

HTML custom iframe element to set the frame's content from the node's innerHTML:

HTML custom iframe element to set the frame's content from the node's innerHTML:

JavaScript
1
2
3
4
5
6
7
class IFrameSrcHtml extends HTMLIFrameElement {
  constructor () {
    super();
    this.srcdoc = this.innerHTML;
  }
}
customElements.define('iframe-srchtml', IFrameSrcHtml, { extends: 'iframe' });

HTML
<iframe is="iframe-srchtml"> <b>test</b> </iframe>

Related: https://stackoverflow.com/questions/53480991/creating-custom-node-to-extend-htmliframeelement