javascript automatic execution

Posted on 2004-03-20
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?
Question by:amakalski
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 16

Expert Comment

ID: 10641970
<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);
// -->


LVL 16

Assisted Solution

jaysolomon earned 75 total points
ID: 10641974
setTimeout would be like a sleep copy paste and see results
LVL 12

Accepted Solution

venkateshwarr earned 75 total points
ID: 10642045
For your first question.... you can directly do the function call without onload() function..



 function welcomeuser()

LVL 12

Expert Comment

ID: 10642384
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>
LVL 15

Expert Comment

ID: 10642741
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:

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question