8

I am calling this javascript on page load

document.body.scrollTop = document.documentElement.scrollTop = 0;

I want html page starts from top when loaded, above javascript working fine for chrome, safari(macbook) but not working for safari on iphone, can anybody suggest workaround in javascript only.

Lalji Gajera
  • 471
  • 1
  • 5
  • 10

2 Answers2

4

Posting this here for future visitors from Google. This same error occured to me... The problem was just one CSS rule on body element.

overflow-x: hidden

If this CSS rule exists, remove it and scrollTop should work on mobile Safari.

Skosh
  • 165
  • 1
  • 9
0

As I tested this before, there are problems rendering on ios, but it also depends on the version of the OS for example, for an iPad pro, there is no problem! But on iPad air you there isn't much to do! so what you can do is to make your code compatible like:

document.scrollingElement.scrollTop

it should give you the right solution.

AxonCodes
  • 1
  • 1