1

I have a component with an iframe like this:

<iframe [innerHTML]="html"></iframe>

if I do:

<div [innerHTML]="html"></div>

it works fine. But I need it to be an iframe for it has customs styles and scripts that must run outside the current page's context.

I've tryed using "DomSanitizer" with no effect

this.html = this.sanitizer.bypassSecurityTrustHtml(someHtmlStuff);

what could be the cause? The iframe ends up completelly empty and its html cannot be inspected in chrome's inspector

user5328504
  • 734
  • 6
  • 21

1 Answers1

0

this fixed it:

--- TEMPLATE ---

 <iframe [src]="html"></iframe>

----- CODE -----

this.html = this.sanitizer.bypassSecurityTrustResourceUrl("data:text/html;charset=utf-8,"+this.dialogRef.config.data.replace("\n",""));

the weird things to notice are

  1. I had to remove line breaks
  2. I had to concatenate this string "data:text/html;charset=utf-8,"
user5328504
  • 734
  • 6
  • 21