Rupam Datta
Rupam Datta

Reputation: 1879

JavaScript setInterval for opera mini and other mobile browsers

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/

Upvotes: 2

Views: 1277

Answers (4)

Prathamesh Rasam
Prathamesh Rasam

Reputation: 436

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

Upvotes: 0

alpham8
alpham8

Reputation: 1362

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.

Upvotes: 1

Kaiido
Kaiido

Reputation: 136746

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.

Upvotes: 3

JRulle
JRulle

Reputation: 7568

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);
  });

Upvotes: 0

Related Questions