我想将原始焦点元素设置为iFrame中活动元素的焦点。这是我原来的功能。
// Original
public componentWillMount(): void {
this._originalFocusedElement = getDocument()!.activeElement as HTMLElement;
}
// My attempt
public componentWillMount(): void {
this._originalFocusedElement = i.getDocument()!.activeElement!.contentWindow.document.activeElement
}
但是它给了我编译错误
[ts] Property 'contentWindow' does not exist on type 'Element'. [2339]
有人可以建议我如何将_originalFocusedElement
设置为iframe中的活动元素吗?
答案 0 :(得分:0)
大多数HTMLElement
都没有contentWindow
属性。尝试将其转换为HTMLIFrameElement
。
const iframe = i.getDocument()!.activeElement! as HTMLIFrameElement;
this._originalFocusedElement = iframe.contentWindow.document.activeElement;