Friday 29 December 2017

javascript - Why can't I pass "window.location.reload" as an argument to setTimeout?

I would love some insight into the error I am seeing in
Safari and Chrome with the following line of
code:


setTimeout(window.location.reload,
250);


Chrome reports: />Uncaught TypeError: Illegal
invocation


And Safari: />TypeError: Type error


In
FireFox, the code runs fine. Also, this code runs fine in each of the three browsers:


setTimeout((function() {

window.location.reload();
}),
250);

Chrome and Safari have no
issues with this code:


var say_hello =
function () { alert("hello") };
setTimeout(say_hello,
250);

What is special about
window.location.reload that causes this
error?


(not sure if it's useful or not, but here's a href="http://jsfiddle.net/goggin13/SQ7az/5/" rel="noreferrer">jsfiddle
illustrating this)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...