0

So I have this class that has methods that capture some specific information. One very important method is getViewportWidth.

Due to a bug/feature in Android 2.2 or so, the widths that are reported are not quite accurate for users using this device platform (You can see more about this here: How do I find the virtual viewport/screen width using Javascript?

The workaround seems to be to delay script execution of the whole script. However, because I need to take care of this transparent from the user, I want to instead delay script execution at the function level i.e. at my getViewportWidth function.

So that a user can just call:

MyClass.getViewportWidth();

And the delay would have been taken care of.

So basically, I'm trying to find a way to delay code execution in my getViewportWidth function by 200 milliseconds to accomodate this bug/feature. How can I do this?!

1 Answer 1

2

You can use setTimeout to delay the execution of a function by some milliseconds. Use like:

var text = "Hi!";
setTimeout(function () {
    alert(text);
}, 200); // 200 ms
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.