I don’t know why I have an function like:
<script type="text/javascript">
function setSomeEnvValue() {
myLoadStatus = true;
myColor = 'black';
}
window.onload = setSomeEnvValue();
</script>
I don’t know why IE show error at:
window.onload = setSomeEnvValue();
When I change this code to:
window.onload = setSomeEnvValue;
It makes me crazy. If setSomeEnvValue() has some arguments like setSomeEnvValue(myVar1, myVar2), how can I call it when using it in IE?
Thanks you very much!
In this case, IE has the correct implementation.
When you set a callback (or event handler), such as
window.onload, you’re basically telling the browser that the function that you’re giving it should be executed when that event is triggered.By writing
window.onload = setSomeEnvValue();, you’re saying that the return value of setSomeEnvValue should be called whenever thewindow.onloadevent is triggered. Of course, this may be possible if your function returns a closure, but I’m going to assume that’s not the case here.