Forum Moderators: open
<html>
<head>
<script type="text/javascript" language="JavaScript">
window.onload = setPage('a','b');
function setPage(a,b){
document.getElementById("hide").style.display ="none";
}
</script>
</head>
<body>
<div id="hide">
Hide
</div>
</body>
</html>
yet this does
<html>
<head>
<script type="text/javascript" language="JavaScript">
window.onload = setPage;
function setPage(a,b){
document.getElementById("hide").style.display ="none";
}
</script>
</head>
<body>
<div id="hide">
Hide
</div>
</body>
</html>
The parenthesis will cause the function to execute immediately, and the result gets assigned to window.onload. If you need to call a function that takes parameters, then wrap it in an anonymous function:
window.onload = function () {
setPage('a','b');
};
setPage will then only execute when the anonymous function is called (and the anonymous function is assigned to the window.onload).