We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


javascript automatic execution

amakalski asked
Medium Priority
Last Modified: 2012-08-13
I have
 //javascript functions

1. Is there a way to run one of the functions automatically whenever the page is loaded, besides BODY onLoad event ??

2. Is there in javascript Sleep function that  makes thread to sleep for given time?
Watch Question

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload = function(){
      // Do your onload statements here
      alert("Some onload function is running");
      setTimeout("alert('I was sleeping for just a few :)')", 700);
// -->


Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Adding on to what venkateshwarr said...

If you want to wait until the page COMPLETELY loaded, make sure you put venkateshwarr's code at the very bottom of your page. If you don't, you might get an error. For example, the following code throws an error because the script runs before the form has loaded.

function welcomeuser(){

<input type=text name=welcome>

Also you should not call the function before you define it:

function welcomeuser(){    // defines the function
          // now the function has been defined so we can call it:
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.