Mike Barwick
Mike Barwick

Reputation: 5367

setTimeout() and IE8. Function not being called

I'm searched around Google and even SO, but I can't seem to find a solution here. Case of the Fridays or I'm simply just missing something.

In IE8, this function is not being called. I read that setTimeout() is not compatible with IE8 to some degree, but the work-arounds I can't seem to get working with my snippet of code.

Help, what am I missing or doing wrong?

onStartup: function () {
    loginForm = $('div#login-box');

    setTimeout(function () {
        loginForm.show();
    }, 1000);
},

EDIT: Found issue, this block of code, used for tablet web-apps, was crashing all my js. New question, how do I prevent this function from being run on IE8 - via js.

    // prevent default action when
    // moving finger on ipad/iphone
    document.addEventListener('touchmove', function (event) {
        event.preventDefault();
    }, false);

Upvotes: 0

Views: 843

Answers (1)

Adam Jenkins
Adam Jenkins

Reputation: 55772

It wasn't "crashing" the JS - IE8 encountered an error because the document object doesn't have the addEventListener method in IE8. IE<9 uses attachEvent.

Since you're not concerned with touch events in IE8, then you don't even have to run that code, so just put a conditional around it that checks for the existence of the addEventListener method.

Here's how to solve it:

// prevent default action when
// moving finger on ipad/iphone
if(document.addEventListener) {
 document.addEventListener('touchmove', function (event) {
    event.preventDefault();
 }, false);
}

Upvotes: 2

Related Questions