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!

2
  • Have you looked into the window.onload handler and the setInterval function?
    – Ian Hunter
    Commented Aug 7, 2012 at 4: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 Commented Aug 7, 2012 at 4:36

6 Answers 6

4

Something like this should work:

window.onload = function() {
  setTimeout(banow, 2000);
};
3
  • How exactly would i place this in my page/ or where? -.- Commented Aug 7, 2012 at 4:36
  • 1
    It's JavaScript, so you put it in a <script> block. When the page is done loading, the window.onload function is called and this code runs.
    – Blender
    Commented Aug 7, 2012 at 4:38
  • Ok, thanks for the amazing answer, quick response, thank everyone else also. :D Commented Aug 7, 2012 at 4:41
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(){

}();
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
});
3
0

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

1
  • please never link to that site - here is why: w3fools.com
    – user557846
    Commented Aug 7, 2012 at 4:36
0
<script type="text/javascript">
window.onload=function(){
  alert("hello"); //call your function here
}
</script>
0

You can call onload in body

eg.

<body onload="ip(parameters)">

</body>

Not the answer you're looking for? Browse other questions tagged or ask your own question.