Topic: Inline javascript

Hey all,

I have a bit of a strange problem. I have a javascript function I wrote which scrolls a bit of a div into view. It needs to be initialized in the page like this:

<script type='text/javascript'>
  init_scroller('project_details', 'v', 30);
</script>

After that I can call start_scroll('target_dom'); to scroll to that dom id.

Now I want to to kick start the scroll to the first item when the page loads so I added this line right under the init_scroller method like this:

<script type='text/javascript'>
  init_scroller('project_details', 'v', 30);
  window.onLoad = start_scroll('target_div');
</script>

It works perfectly in Explorer but Firefox ignores the second line. Even if I write this:
<script type='text/javascript'>
  init_scroller('project_details', 'v', 30);
  alert('testing');
</script>

The alert line never gets called in Firefox (it works in explorer.)

Now for the really strange part: It does work if I have Firebug enabled but not in vanilla Firefox. Bit of a head scratcher really.

-- marsvin

Re: Inline javascript

Little update. If I split the commands over two script tags it does work in Firefox too.. So like this it works just fine:

<script type='text/javascript'>
  init_scroller('project_details', 'v', 30);
</script>
<script type='text/javascript'>
  window.onLoad = start_scroll('target_div');
</script>

But it's about as non-DRY as you can get wink

Re: Inline javascript

That's strange ...
Maybe some sort of issue in the "init_scroller" ... sometimes syntax errors result in unpredictable behaviour.

Scriptaculous has Slide effects built in, btw ...

Toby Hede
===================================================
FiniteStateMachine - Software Development for Social Networks
===================================================