2
votes

I'm facing problem using setInterval function in my website. I've a small section of my code below. I'm basically trying to increase the count by 1 and print it on screen.

<div id="test"></div>

<script>

var count = 0;
setInterval(function() {
    document.getElementById('test').innerHTML=count;
    count++;
}, 1000);


</script>  

Edit: I'm not using jquery in the code as it should be quite clear from above. However the problem I'm facing here is when I open the html in opera mini in mobile device, the count it shows is either 1 to 3 or 1 to 4. It does not continue. I've an external url. Please open the url in a mobile device and see the problem. http://fundoophoto.com/raman/Test/

4
Code is working fine jsfiddle.net/g8Lghj7v - Manwal
what problem u face. please mention. It will help to solve your problem. - ketan
it shouldn´t matter if it´s a mobile browser or not. Should work equal. Besauce jQuery does also at mobile devices. Maybe it´s a general problem? But I can´t see it, because your discription is intermediate. - alpham8
@Manwal It works fine in laptop, not in mobile; at least for me. - Rupam Datta
@ketan Added description and a test (external) url. Please open the url in a mobile device. - Rupam Datta

4 Answers

3
votes

Opera Mini doesn't actually executes javascript :

It does this by using a proxy-based architecture. Requests from the user’s handset pass through the carrier’s internet gateway on their way to Opera’s transcoding servers. These servers then forward the request to the server. Opera Mini requests pass through Opera’s servers.
The server sends the response back as normal — when this is received by the Opera transcoding servers, they parse the markup and styles, execute the JavaScript, and transcode the data into Opera Binary Markup Language (OBML). This OBML data is progressively loaded by Opera Mini on the user’s device. Think of it as an interactive snapshot of a document’s state, which is similar in form to a PDF.

You should read this page about this feature : https://dev.opera.com/articles/opera-mini-and-javascript and particularly this section about setInterval and setTimeoutfunctions.

This means that if you use setInterval to invoke a function, it will be called a maximum of n times where n is the quotient of the timeout divided by the interval. If the interval is 1000 milliseconds, the function will be executed a maximum of five times (in newer versions of Opera Mini) before the entire script is paused (5000 ÷ 1000 = 5). If the interval is 5000 milliseconds, it will be executed no more than once before pausing.

1
votes

This is an exceptional thing to mobile browser. As I read here its meant to be fast and effective. So, if your script takes to much time, it is interrupted by the browser itself. That´s a feature of opera mini.

0
votes

I think the DOM is not fully loaded when yourbeddingnumbering called. Try wrapping it in a DOM ready event listener.

  var count = 0;
  document.addEventListener("DOMContentLoaded", function(event) {
setInterval(function() {
    document.getElementById('test').innerHTML=count;
    count++;
}, 1000);
  });
0
votes

When browsing the Web in Opera Mini JavaScript is processed by the proxy server(opera servers), and is merely rendered on the device

before the page is sent to the mobile device, its onLoad events are fired and all scripts are allowed a maximum of two seconds to execute. The setInterval and setTimeout functions are disabled, so scripts designed to wait a certain amount of time before executing will not execute at all