0

Possible Duplicate:
Javascript that executes after page load

script type="text/javascript">
function ip(ban, win) {

    var width = 15;
    var height = 10;

    if (newwin) {



}

</script>
</head>
<b><input type="button" value="Check" onclick="banow();"/></center></b>

Does anyone know if it is possible and how to make this function start on page load, preferably with a interval? I am new to all this, extra help would be appreciated!

Community
  • 1
  • 1
  • Have you looked into the `window.onload` handler and the `setInterval` function? – Ian Hunter Aug 07 '12 at 04:33
  • I wish I knew more about scripting or w/e. I have no clue about how to use the window.onload handler. Any suggestions where to go to learn about it or something? :O – Roger Hippensteel Aug 07 '12 at 04:36

6 Answers6

4

Something like this should work:

window.onload = function() {
  setTimeout(banow, 2000);
};
Blender
  • 289,723
  • 53
  • 439
  • 496
1

You can just use the onload event, apply the onload event to an event listener, or put a () right after the closing curly bracket of your function.

//e.g. 1:
window.onload = function(){
  setTimeout(function(){
    function_to_call();
  }, 1000);
};

//e.g. 3:
window.addEventListener("load", function(){
  setTimeout(function(){
    function_to_call();
  }, 1000);
}, false);


//e.g. 2:
function function_to_call(){

}();
jeremy
  • 9,965
  • 4
  • 39
  • 59
0

In jQuery:

$(function(){
     // your methods here, will be called after page has been loaded
     setInterval(functionName, 1000); //replace functionName with your function, 1000 is millisecond
});
lorraine batol
  • 6,001
  • 16
  • 55
  • 114
  • 2
    jQuery is a lightweight "write less, do more" JavaScript library. So you want "write more", ok fine. What's with the attitude anyway? – lorraine batol Aug 07 '12 at 04:41
  • [When is “use jQuery” not a valid answer to a JavaScript question?](http://meta.stackexchange.com/questions/45176/when-is-use-jquery-not-a-valid-answer-to-a-javascript-question) –  Aug 07 '12 at 04:43
  • it's actually in this case not less code... – jeremy Aug 07 '12 at 04:44
0

You need body and onload event, please check: http://www.w3schools.com/jsref/event_body_onload.asp

  • please never link to that site - here is why: http://www.w3fools.com –  Aug 07 '12 at 04:36
0
<script type="text/javascript">
window.onload=function(){
  alert("hello"); //call your function here
}
</script>
WatsMyName
  • 4,240
  • 5
  • 42
  • 73
0

You can call onload in body

eg.

<body onload="ip(parameters)">

</body>
Shrujan Shetty
  • 2,298
  • 3
  • 27
  • 44