Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use javascript timer in a mobile browser
    text
    copied!<p>I am using IE in a mobile browser. I add a javascript function to a button that when the User clicks it says 'hello'.</p> <p>This works.</p> <p>I then add a timer.</p> <p>On a desktop browser it works.</p> <p>it does not work on my mobile browser.</p> <p>This is my code. (note I Had just tried placing an alert('hi'); in the swapImages() and that did not work either.</p> <pre><code> var div = document.getElementById('divImage'); var imgCached = document.getElementById('imgCached'); document.execCommand("BackgroundImageCache", false, true); function OnImgLoaded() { img1.src = imgCached.src; } var interval = 30; var _timer; var _index = 0; function test() { _timer = setInterval('swapImages()', interval); } function swapImages() { imgCached.onload = OnImgLoaded(); imgCached.src = 'my server url~/' + '0000' + _index + '.jpg'; _index = _index + 1; if (_index == 10) { _index = 0; clearTimeout(_timer); } } </code></pre> <p>UPDATE!! I had been runningit on Chrome desktop and not IE. I am mow testing it in IE desktop. I get the same erro so now I can debug.</p> <p>The error is this line: img1.src = imgCached.src;</p> <p>It tells me: Unable to get property 'src' of undefined or null reference</p> <p>I have changed the code to: var imgLive = document.getElementById('imgLive'); (I have renamed the img control)</p> <pre><code>function OnImgLoaded() { imgLive.src = imgCached.src; } </code></pre> <p>I get the same error.</p> <p>I look in Source and the control is correctly named..</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload