javascript - Which browsers (and versions) support callback arguments for setTimeout and setInterval? - Stack Overflow

According to WHATWG and MDN, window.setTimeout and window.setInterval have the formvar handle = window.

According to WHATWG and MDN, window.setTimeout and window.setInterval have the form

var handle = window.setTimeout( handler [, timeout [, arguments... ] ] );
var handle = window.setInterval( handler [, timeout [, arguments... ] ] );

Most sources say (generic) Internet Explorer doesn't support the optional arguments.
Is there a list of browsers and versions that do and do not support it?

An example of the way to test for support would be

<html>
<head><title>test</title></head>
<body>
setTimeout: <span id="t">testing..</span><br/>
setInterval: <span id="i">testing..</span>
<script type="text/javascript">
t = window.setTimeout( // setTimeout
    function (b) { // callback
        document.getElementById('t').innerHTML = (b || false); // test for arg1
    },
    0,
    true // arg1
);
i = window.setInterval( // setInterval
    function (b) { // callback
        document.getElementById('i').innerHTML = (b || false); // test for arg1
        window.clearInterval(i);
    },
    0,
    true // arg1
);
</script>
</body>
</html>

With expected result true and result on failure as false.

According to WHATWG and MDN, window.setTimeout and window.setInterval have the form

var handle = window.setTimeout( handler [, timeout [, arguments... ] ] );
var handle = window.setInterval( handler [, timeout [, arguments... ] ] );

Most sources say (generic) Internet Explorer doesn't support the optional arguments.
Is there a list of browsers and versions that do and do not support it?

An example of the way to test for support would be

<html>
<head><title>test</title></head>
<body>
setTimeout: <span id="t">testing..</span><br/>
setInterval: <span id="i">testing..</span>
<script type="text/javascript">
t = window.setTimeout( // setTimeout
    function (b) { // callback
        document.getElementById('t').innerHTML = (b || false); // test for arg1
    },
    0,
    true // arg1
);
i = window.setInterval( // setInterval
    function (b) { // callback
        document.getElementById('i').innerHTML = (b || false); // test for arg1
        window.clearInterval(i);
    },
    0,
    true // arg1
);
</script>
</body>
</html>

With expected result true and result on failure as false.

Share Improve this question asked Sep 30, 2012 at 0:27 Paul S.Paul S. 66.4k9 gold badges128 silver badges143 bronze badges 2
  • 1 Since it is so easy to simply use an anonymous function to pass extra arguments and it runs everywhere, why not just use that and avoid the headaches? – Jeremy J Starcher Commented Sep 30, 2012 at 3:16
  • 1 It is a question I couldn't find an actual answer to anywhere, as in, the answers assumed every version of each browser is the same, so I went to find out and decided to share. – Paul S. Commented Sep 30, 2012 at 12:45
Add a ment  | 

1 Answer 1

Reset to default 8

Using a test based upon the example code in the question and BrowserShots for the browsers, here is a table of browser support

Browser  Version  setTimeout  setInterval
Chrome     4+      true        true         Lowest version testable
Firefox    3+      true        true         Did not test lower versions
MSIE       6       false       false
MSIE       7       false       false
MSIE       8       false       false
MSIE       9       false       false
MSIE      10       true        true
Opera                                       Not tested

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745631388a4637130.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信