Last Updated: October 26, 2016
· jastkand

Enable/Disable Scrolling in iPhone/iPad’s Safari

Today working on mobile theme for one portal I was needed to prevent scrolling of the screen when the popup window is opened.

After some googling I found the good and simple solution of this issue.

To prevent user from scrolling the screen you need to redefine touch move event

document.ontouchmove = function(e){ e.preventDefault(); }

Then if you need to enable screen scrolling you need to make a little tricky

document.ontouchmove = function(e){ return true; }

That works for me, and I like it.

4 Responses
Add your response

Wonderful! I've been trying with overflow:hidden; and it was causing page shift. This works like a charm.

over 1 year ago ·

I've found several attempts at this online but this method is the only one that worked well for me. Thank you very much for posting.

over 1 year ago ·

It's working fine but It's prevent the popup scroll. How to enable popup container scroll?

over 1 year ago ·

good for me on android
but, when the body page is block from scrolling, i cannot scroll my div or modal

How to enable my div only in javascript?

Thank you

over 1 year ago ·