How do I get the Window object from the Document object?

前端 未结 6 1693
太阳男子
太阳男子 2021-01-01 08:29

I can get window.document but how can I get document.window? I need to know how to do this in all browsers.

6条回答
  •  感动是毒
    2021-01-01 09:03

    I opted to inject the DOCUMENT token from @angular/platform-browser:

    import { DOCUMENT } from '@angular/platform-browser'
    

    and then access the parent:

    constructor(@Inject(DOCUMENT) private document: any) {
    }
    
    public ngOnInit() {
      // this.document.defaultView || this.document.parentWindow;
    }
    

提交回复
热议问题