Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.scrollTo is not working in Internet Explorer 11

I want the scrollbar to be positioned on top by default as soon as I launch the page.But the below code works fine in chrome but not in IE11.

If I try to debug the script, the scrollbar is positioned on top.

$(document).ready(function () {
  window.scrollTo(0,0);
 }

I tried different solution online such as

$(window).scroll().scrollTop(0);
document.body.scrollTop(0);

But nothing worked in IE.Kindly help me

like image 583
Tanu Avatar asked Oct 07 '16 03:10

Tanu


People also ask

What is window scrollTo?

Definition and Usage The scrollTo() method scrolls the document to specified coordinates.

Can t Scroll in Internet Explorer 11?

1)update mouse driver. 2) Installed windows updates. 3) cleared browser history and cleared browser cached files. 4) removed IE from windows and added again.


2 Answers

Though this is a very old question, but updating here for someone looking for a solution.

Try using:

element.scrollTop = 0;

This should work on all browsers.

like image 123
vidit chauhan Avatar answered Nov 14 '22 21:11

vidit chauhan


Try using

$('body,html').scroll().scrollTop(0);

or

$('body,html').animate({scrollTop:0});
like image 36
Rani Moreles Rubillos Avatar answered Nov 14 '22 23:11

Rani Moreles Rubillos