Javascript work around

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 321
  • Loc: Canada

Post 3+ Months Ago

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
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 321
  • Loc: Canada

Post 3+ Months Ago

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
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

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>
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 321
  • Loc: Canada

Post 3+ Months Ago

hi SpooF

Did as you indicated but it did not work.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 321
  • Loc: Canada

Post 3+ Months Ago

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>
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 321
  • Loc: Canada

Post 3+ Months Ago

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

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 81 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.