0

I am trying to user JavaScript function setInterval(callback, delay). My code is working on all browsers(IE, Chrome, Firefox, etc) except when i run the same code to on the browser(IE) of device running WINDOWS CE , it stop at function setInterval(func, delay). Alerts work on device setinterval, but alert inside function tick is not called.

<body onload="startTimer(5000)">
//Other HTML tags or data
</body>

<script type="text/javascript">

function startTimer(sessionTime){ 
        alert("function called startTimer");
        var timerInterval = setInterval(tick, sessionTime)
        }

        function tick() {
        alert("TICK FUCTION IS CALLED")
        //Do something
        }
</script>

I also tried to use setTimeout(), it is also not working either on windows ce device. Due to some restriction i have to use onload instead of window.onload I need to do this interval thing in plain old JavaScript cannot use JQuery for some reason.

Sidharth
  • 1,402
  • 2
  • 16
  • 37
  • Possible duplicate of [setInterval & Internet Explorer](https://stackoverflow.com/questions/13566159/setinterval-internet-explorer) – Grabatui Sep 03 '19 at 06:24
  • What version of IE was installed to the device? I'd recall `setInterval` was added into IE in version 7. – Teemu Sep 03 '19 at 06:26
  • @Grabatui That question is says it is not working on IE browser(possibly on PC), but code is working on PC but not on Windows CE device browser. – Sidharth Sep 03 '19 at 06:34
  • @Teemu the windows device has a restricted access for everything, device image do not has access to view the IE version . – Sidharth Sep 03 '19 at 06:35
  • You can't access IE's Help menu and its About section? – Teemu Sep 03 '19 at 06:37
  • @Teemu Device browser don't have HELP menu or About section. It is all restricted due to security issues as it is a medical device(Motorolla MC55a) – Sidharth Sep 03 '19 at 06:40
  • The version could be found by alerting `navigator.userAgent`, or `ScriptEngineMajorVersion() + '.' + ScriptEngineMinorVersion()`. But despite the version, `setTimeout` should work. If it doesn't, I'm afraid you're out of luck with this. – Teemu Sep 03 '19 at 07:10
  • @Teemu version :: `Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11)` – Sidharth Sep 03 '19 at 07:34

1 Answers1

1

Since both setInterval and setTimeout are methods of window object and you can't access its onload method for some reason that's where I'd search for a problem. Starting with: !!window and !!window.setInterval. Hope it can serve as some hint, I'd rather make it a comment.

  • I did try it with both `window.setInterval` and `!!window.setInterval` but its not working – Sidharth Sep 03 '19 at 08:11
  • I mean, if `!!window.setInterval` evaluates to false your `window` object has no such property, can you print `window` object to the console? – Kuba Michalski Sep 03 '19 at 08:24
  • The device i am using does not let me open the console. it has restricted access (device : Motorolla MC55A). – Sidharth Sep 03 '19 at 08:26
  • I'm afraid then, as Teemu said you're out of luck :( if alerting `!!window.setInterval` shows you false it clearly doesn't exist in the `window` object, I don't know why it's the case. – Kuba Michalski Sep 03 '19 at 09:24
  • And if you put `!!window.setInterval` into the first one? The point is to check if it exists so you can put it to new alert at the very top it doesn't matter really. – Kuba Michalski Sep 03 '19 at 09:39
  • `alert(!!window)` return TRUE and ` Is there alert(!!window.setInterval)` return FALSE. I there any other way i can achieve what i want? – Sidharth Sep 03 '19 at 09:46
  • Honestly I don't know, I don't want to misguide you in any way and I think any answer at that point is likely to be more helpful than mine. The only ways I see from now are: **a)** figuring out what's wrong with your `window` object. Last tip I can give you is to take a look at your `window` object keys with `document.write(Object.keys(window).sort().join(' | '))` (if document hopefully exists for you) **b)** make your own implementation but I can't advice it to you because it can be a huge overkill, just in case you won't find any help, this is all that comes to my mind – Kuba Michalski Sep 03 '19 at 10:28
  • 1
    It's __IE6__, it was dead for a long before `Object.keys` was even born. `alert` is also a DOM method, i.e. a method in `window`, but it seems to work. @Sidharth If both `alert('setTimeout' in window)` and `alert('setInterval' in window)` show false, the timers are stripped out of the environment, and there's nothing you can do to achieve what you need. – Teemu Sep 03 '19 at 11:08
  • @Teemu Thank you for the suggestion, But i have moved it from `setInterval` to recursive call of `setTimeout` – Sidharth Sep 03 '19 at 11:15
  • It turns out that device's IE browser does not support setInterval, so i accomplished the task using recursive setTimeout method. Thanks for let me know how to check what default methods are available and what not. Gonna Mark your answer correct for this. – Sidharth Oct 10 '19 at 12:45