943,899 Members | Top Members by Rank

Ad:
May 17th, 2009
0

Javascript window onload

Expand Post »
hi, how to use the window onload event on javascript.. for example i got a function and i want that function to execute during page load. any ideas is greatly appreciated... thanks...
Similar Threads
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
May 17th, 2009
0

Re: Javascript window onload

Here is a sample code:
html Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function load()
  5. {
  6. //Put your code here
  7. }
  8. </script>
  9. </head>
  10.  
  11. <body onload="load()">
  12.  
  13. </body>
  14. </html>
Last edited by codestips; May 17th, 2009 at 8:45 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
codestips is offline Offline
4 posts
since May 2009
May 17th, 2009
0

Re: Javascript window onload

The best way to do it:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Test Page</title>
  4. <script type="text/javascript">var myFunc = function() {
  5. alert("Hello World!");
  6. };
  7.  
  8. window.onload = myFunc;
  9. </script>
  10. </head>
  11. <body>
  12. </body>
  13. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
May 20th, 2009
0

Re: Javascript window onload

thanks..
Reputation Points: 19
Solved Threads: 115
Nearly a Posting Virtuoso
cguan_77 is offline Offline
1,317 posts
since Apr 2007
May 20th, 2009
0

Re: Javascript window onload

You can of course do it with W3 event listeners, IE attatch event, or JQuery as well, but you knew that.
Reputation Points: 14
Solved Threads: 22
Junior Poster
JugglerDrummer is offline Offline
138 posts
since Apr 2009
May 21st, 2009
0

Re: Javascript window onload

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var x=0
  5. function displaymessage()
  6. {
  7. while (x==0)
  8. {
  9. x=0
  10. alert("NO!");
  11. }
  12. }
  13. </script>
  14. </head>
  15.  
  16. <body onload="displaymessage()">
  17. <form>
  18.  
  19. </form>
  20. </body>
  21. </html>
Last edited by Ezzaral; May 21st, 2009 at 1:26 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
koolhq is offline Offline
9 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Make Iframe Editable
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript Regular Expression Testing Utility





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC