1

I'm trying to inject a CSS file to a third party iframe that I need to change the styling.

I thought of using

ngOnInit() {
...

this.myIframe.nativeElement.document.head.appendChild('style.css')

}

but it is not working for some reason beyond my grasp.

Any help will be appreciated.

Cheers

2 Answers 2

1

This workaround will work if your Iframe is not from a different domain. You will get a cross-browser error. Template

<iframe #myIframe></iframe>

Component

@ViewChild('myIframe') public myIframe;
..........
ngAfterViewInit() {
  const iframDoc = this.myIframe.nativeElement.contentWindow.document;
  .....
  iframDoc.head.appendChild('style.css');
}
.....
Sign up to request clarification or add additional context in comments.

Comments

0

It isn't possible to inject code like I thought it was so I ended up overriding the CSS when the SCSS file that controlled that page was compiled.

In some occasions, I had to use the whole inheritance chain to get a field to behave the way it was required.

Thank you for your input @SuhelKhan

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.