Javascript work around

  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post September 9th, 2011, 9:35 pm

Hi All

I current use the following in my HTML body:

Code: [ Select ]
<body onLoad="setInterval('JavaScript:heart()',1000);init();">


I would like to replace this completely with javascript.
I have tried the following but it does not work.

Code: [ Select ]

<body>

<script language="javascript">

window.onload = function() {
  setInterval(function heart(), 1000);
}
function intro()

</script>
  1. <body>
  2. <script language="javascript">
  3. window.onload = function() {
  4.   setInterval(function heart(), 1000);
  5. }
  6. function intro()
  7. </script>


Can someone give me any suggestions

thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post September 9th, 2011, 9:35 pm

  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post September 9th, 2011, 10:29 pm

I managed to get it half working by doing the following:

Code: [ Select ]
<script language="javascript">
window.onload = function() {
  setInterval(function heart(), 1000);
}
function heart()
{
// stuff here
}
</script>
  1. <script language="javascript">
  2. window.onload = function() {
  3.   setInterval(function heart(), 1000);
  4. }
  5. function heart()
  6. {
  7. // stuff here
  8. }
  9. </script>


and

Code: [ Select ]
<script language="javascript">
function init()
{
// stuff here
}
window.onload = init;
</script>
  1. <script language="javascript">
  2. function init()
  3. {
  4. // stuff here
  5. }
  6. window.onload = init;
  7. </script>


The function init() appears to load OK

The function heart() does not seem to load

Anyone have suggestions

Thanks
http://www.schembrionics.com
The Ultimate Solutions Center
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post September 9th, 2011, 10:42 pm

You don't need to use the keyword function for the first one.

Code: [ Select ]
  <script language="javascript">
  window.onload = function() {
   setInterval(heart, 1000);
  }
  function heart()
  {
  // stuff here
  }
  </script>
  1.   <script language="javascript">
  2.   window.onload = function() {
  3.    setInterval(heart, 1000);
  4.   }
  5.   function heart()
  6.   {
  7.   // stuff here
  8.   }
  9.   </script>
#define NULL (::rand() % 2)
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post September 10th, 2011, 4:08 pm

hi SpooF

Did as you indicated but it did not work.
http://www.schembrionics.com
The Ultimate Solutions Center
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post September 10th, 2011, 4:33 pm

I managed to get it partially working with the following:

Code: [ Select ]
<script type="text/javascript">
window.onload=setInterval('heart();',1000);
function heart()
 {
 // stuff here
 }
 </script>
  1. <script type="text/javascript">
  2. window.onload=setInterval('heart();',1000);
  3. function heart()
  4.  {
  5.  // stuff here
  6.  }
  7.  </script>
http://www.schembrionics.com
The Ultimate Solutions Center
  • wpas
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jul 12, 2010
  • Posts: 214
  • Loc: Canada
  • Status: Offline

Post September 10th, 2011, 6:02 pm

After some hunting on the internet I finally came up with a very simple solution that works great:

Code: [ Select ]
<script type="text/javascript">
window.onload = function() {
setInterval('heart();',1000);
init();
}
</script>
  1. <script type="text/javascript">
  2. window.onload = function() {
  3. setInterval('heart();',1000);
  4. init();
  5. }
  6. </script>


Whats good about the code is that you can load as many functions as you want at one time with only one script

Hope this helps others if you want to replace the HTML onload function with the javascript window.onload function
http://www.schembrionics.com
The Ultimate Solutions Center

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 202 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.