While working on a custom directive that requires scroll position, I discovered that all major browsers support window.scrollY
, except for IE11 which needs
document.documentElement.scrollTop
.
Therefore, I am attempting to check if the current browser is IE11:
ngOnInit(){
this.isIE11 = !!window.MSInputMethodContext && !!document.documentMode;// tslint:disable-line
this.checkScrollPosition();
}
However, I am encountering TypeScript errors stating that
property MSInputMethodContext doesn't exist on type Window
and property documentMode doesn't exist on type Document
. Even though the code works fine in Chrome, Safari, and IE11.
1) Am I correct in assuming that this will work fine since TypeScript will be translated to pure JS where these properties will be accessible?
2) Should I suppress this warning (if so, how?), or should I try a different browser detection approach?
I have attempted to add the following lines, but with no success thus far:
//tslint:disable-line
//noinspection TypeScriptUnresolvedProperty