There are many questions about preventing user-initiated (i.e., mouse, touch, keyboard) scrolling via javascript. In this case, I am creating a component within a CMS that needs to stop another CMS component from scrolling itself into view. I do not have access to the other CMS component's code (which is also heavily obfuscated).
I have tried disabling typical ways of forcing scrolling with the following code, yet the other CMS still scrolls into view, a second or two after the following code runs:
Element.prototype.scrollIntoView = function(alignWithTop){
console.log("******** scrollIntoView: " + this.getAttribute("id"));
};
Element.prototype.scrollIntoViewIfNeeded = function(alignWithTop){
console.log("******** scrollIntoViewIfNeeded: " + this.getAttribute("id"));
};
Element.prototype.scrollByLines = function(){
console.log("******** scrollByLines: " + this.getAttribute("id"));
};
Element.prototype.scrollByPages = function(){
console.log("******** scrollByPages: " + this.getAttribute("id"));
};
Element.prototype.focus = function(){
console.log("******** focus: " + this.getAttribute("id"));
};
window.scroll = function(xpos,ypos){
console.log("******** scroll: " + xpos+","+ypos);
}
window.scrollTo = function(xpos,ypos){
console.log("******** scrollTo: " + xpos+","+ypos);
}
window.scrollBy = function(xpos,ypos){
console.log("******** scrollBy: " + xpos+","+ypos);
}
jQuery.fn.scrollTop = function(){
console.log("!!!!!!!! scrollTop");
};
jQuery.fn.animate = function(){
console.log("!!!!!!!! animate");
};
jQuery.fn.click = function(){
console.log("!!!!!!!! click");
};
I can set window.onscroll to force a call to window.scrollTo(0,0) for a period of time, but that seems unsatisfactory since it looks jumpy and prevents user-initiated scrolling, which I do not want to prevent.
Is there some other way javascript (or jQuery) can force a scroll that I am missing in the above code?