admin管理员组文章数量:1026103
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
.
- 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
1 Answer
Reset to default 8Using 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
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
.
- 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
1 Answer
Reset to default 8Using 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
本文标签:
版权声明:本文标题:javascript - Which browsers (and versions) support callback arguments for setTimeout and setInterval? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745631387a2160185.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论