iframe inside angular2 component, Property 'contentWindow' does not exist on type 'HTMLElement'

前端 未结 7 2057
一整个雨季
一整个雨季 2020-12-03 07:44

I have an iframe inside a angular2 component, and I am trying to change the content of the iframe by accessing the contentWindow.
The iframe should contain a simple butt

7条回答
  •  一整个雨季
    2020-12-03 08:26

    I solved the problem in the following way:

    const element: HTMLIFrameElement = document.getElementById('iframe') as HTMLIFrameElement;
    const iframe = element.contentWindow;
    if (iframe !== null) {
      ...
    }
    

提交回复
热议问题