Solved

javascript automatic execution

Posted on 2004-03-20
5
1,213 Views
Last Modified: 2012-08-13
I have
<script>
 //javascript functions
</script>

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?
0
Comment
Question by:amakalski
[X]
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
5 Comments
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10641970
<html>
<head>
<title></title>
<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);
}
// -->
</script>
</head>

<body>

</body>
</html>
0
 
LVL 16

Assisted Solution

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

Accepted Solution

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

<script>

welcomeuser();

 function welcomeuser()
 {
    alert("welcome...");
 }

</script>
0
 
LVL 12

Expert Comment

by:lil_puffball
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.

<script>
welcomeuser();
function welcomeuser(){
document.forms[0].welcome.value="Welcome!";
}
</script>

<form>
<input type=text name=welcome>
</form>
0
 
LVL 15

Expert Comment

by:JakobA
ID: 10642741
Also you should not call the function before you define it:

<script>
function welcomeuser(){    // defines the function
    document.forms[0].welcome.value="Welcome!";
}
          // now the function has been defined so we can call it:
welcomeuser();
</script>
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

738 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