5

A few questions here:

  1. Is there anyway to keep iOS from freezing javascript on the page while scrolling?

  2. Does iOS freeze javascript when your in another tab or if you switch apps?

  3. Are there any other major javascript limitations on iOS?

James Kyle
  • 4,138
  • 4
  • 28
  • 41

2 Answers2

6

iOS 6.x suspends all event timers in response to touch events like scrolling and has a tendency not to start up all the timers again once the event is done. It's a well known iOS 6 bug that is super-annoying. It pretty much breaks parallax and stuff. Some people have resorted to building their own scroll functionality.

Here's another StackOverflow on the same topic: iOS 6 safari, setInterval doesn't get fired

and another: setInterval pauses in iphone/ipad (mobile Safari) during scrolling

and here is the closest thing you'll get to a bug report on it (Apple doesn't make bug reports public to maintain the illusion of perfection, so developers made their own bug site): http://openradar.appspot.com/12756410

This bit of code will unfreeze timers that are broken / lost / destroyed by iOS during a page scroll: https://gist.github.com/ronkorving/3755461

This is another attempt to fix the freeze: iOS 6 js events function not called if has setTimeout in it

Unfortunately, there is nothing you can do to fire events WHILE page scrolling. Like fade out a back-to-top link when scrolling up the page. When it comes to scrolling, iOS6 is incapable of rubbing it's tummy and patting it's head. (iOS5 works fine, btw. This is a regression)

Community
  • 1
  • 1
mrbinky3000
  • 4,055
  • 8
  • 43
  • 54
  • There's another workaround mentioned here: http://stackoverflow.com/questions/10482227/javascript-dom-changes-in-touchmove-delayed-until-scroll-ends-on-mobile-safari -> build your own scroll function... – chaenu Jan 27 '14 at 14:41
1

To answer the third question, a decent-sized limitation is that sometimes innerHTML just plain doesn't work. From the accepted answer:

It happens when the CPU of the phone is very busy (say 100%). Then the rendering engine sometimes forget about innerHTML settings.

The solution included in my unify project is to test if there is an element in childNodes, otherwise apply it again.

Community
  • 1
  • 1
sdleihssirhc
  • 42,000
  • 6
  • 53
  • 67
  • 1
    [John McKerrell blogged about the Mobile Safari innerHTML bug](http://blog.johnmckerrell.com/2007/03/07/problems-with-safari-and-innerhtml/) way back in 2007, as well. – sdleihssirhc Dec 02 '11 at 20:02