Author Topic: Yet Another code question posed to the gurus  (Read 1840 times)

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Yet Another code question posed to the gurus
« on: November 02, 2005, 01:31:59 PM »
Ok.  I'm about ready blow my top.

I've got the following code in my webpage:

<body class="body" onLoad="SetMenu()">

This triggers the javascript function SetMenu after the page is loaded.  It works perfectly in IE.

Mozilla ignores it.  Why?  Surely such a vanilla functionality is duplicated in Firefox?

But for the life of me I can't figure out what it is.  I've searched the web and the forums and they all either vaguely refer to the function call in Firefox or they imply that the onLoad, as I've got it written, works in IE and Firefox both.  It doesn't.  

Can anyone tell me how to do in Firefox what the above code does in IE?  Please? e?  Spriggan? Tage?
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers

  • Administrator
  • Level 96
  • *****
  • Posts: 19211
  • Fell Points: 17
  • monkeys? yes.
    • View Profile
    • herb's world
Re: Yet Another code question posed to the gurus
« Reply #1 on: November 02, 2005, 02:05:57 PM »
I've found that FireFox, due it's being so wrapped up in "strict" functionality, ends up missing a lot of stuff. onLoad is *supposed* to work, but that doesn't mean it will. I can't remember if Firefox has an error console. If so, you could use that to get an exact error, I might be able to work with it better.

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #2 on: November 02, 2005, 02:19:43 PM »
Firefox does have a javacript console but it's not throwing an error.  It just doesn't work.

How does one tell Firefox to run a javascript function only once everything is loaded?  That's all I want to do really.

If you don't usually work with Firefox, and thus don't know how to do this off the top of your head, I wouldn't want you to spend time figuring it out.  I would feel bad if you did.

"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Eric James Stone

  • Level 12
  • *****
  • Posts: 519
  • Fell Points: 0
    • View Profile
    • Eric James Stone's Website
Re: Yet Another code question posed to the gurus
« Reply #3 on: November 02, 2005, 02:30:23 PM »
It works in my FireFox.
Code: [Select]
<HTML>
<HEAD>
<SCRIPT>
function SetMenu(){
     alert(1);
}
</SCRIPT>
</HEAD>
<body class="body" onLoad="SetMenu()">
Test
</body>
</HTML>
Eric James Stone
Nebula Award Nominated Author
Read my serialized novel Unforgettable for free online.

The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers

  • Administrator
  • Level 96
  • *****
  • Posts: 19211
  • Fell Points: 17
  • monkeys? yes.
    • View Profile
    • herb's world
Re: Yet Another code question posed to the gurus
« Reply #4 on: November 02, 2005, 02:38:40 PM »
Quote
If you don't usually work with Firefox, and thus don't know how to do this off the top of your head, I wouldn't want you to spend time figuring it out.  I would feel bad if you did.

I wouldn't feel bad about it. Most geeks who choose to go figure it out are doing it because they want to know themselves. They like doing that.

Unfortunately, I haven't really worked with JavaScript for a very long time, so I won't be much help, I think, aside from the obvious but often forgotten by everyone "check the options." You can turn JavaScript off in Firefox in the "web features" section. Make sure it's on.  If it *is* enabled, you might want to click the "Advanced" button and see if any specific functions are turned off.

Eric James Stone

  • Level 12
  • *****
  • Posts: 519
  • Fell Points: 0
    • View Profile
    • Eric James Stone's Website
Re: Yet Another code question posed to the gurus
« Reply #5 on: November 02, 2005, 02:55:37 PM »
Quote
I wouldn't feel bad about it. Most geeks who choose to go figure it out are doing it because they want to know themselves. They like doing that.

I think e's got the situation pegged.
Eric James Stone
Nebula Award Nominated Author
Read my serialized novel Unforgettable for free online.

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #6 on: November 02, 2005, 04:02:58 PM »
It's gotten more interesting now.  I loaded up Eric's example code in a blank page and it worked in my Mozilla too.  So it's not my browser settings.

But I still don't know why it doesn't work on MY pages.  I found an inelegant and spotty workaround for this weeks ago and have been using that since so something in my page from long ago screws this up somehow.  Thanks for the help, if you have any more thoughts let me know.
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Eric James Stone

  • Level 12
  • *****
  • Posts: 519
  • Fell Points: 0
    • View Profile
    • Eric James Stone's Website
Re: Yet Another code question posed to the gurus
« Reply #7 on: November 02, 2005, 04:11:16 PM »
If you want to, email me the code (anything at ericjamesstone d0t c0m) or give a URL where the code is posted.
Eric James Stone
Nebula Award Nominated Author
Read my serialized novel Unforgettable for free online.

The Holy Saint, Grand High Poobah, Master of Monkeys, Ehlers

  • Administrator
  • Level 96
  • *****
  • Posts: 19211
  • Fell Points: 17
  • monkeys? yes.
    • View Profile
    • herb's world
Re: Yet Another code question posed to the gurus
« Reply #8 on: November 02, 2005, 04:35:28 PM »
hrm... I seem to remember Firefox having trouble executing some JavaScript in a recent page I did. I think it was an HTML problem. Firefox being picky about that. email me the code (page and JavaScript) too and I'll look at it. I'm trying to remember what it was that fixed the problem.

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #9 on: November 02, 2005, 04:46:10 PM »
Ah ha.  I'm willing to bet now that the onLoad event in Firefox does not wait for the whole page to be loaded before it fires.  Now I just have to figure out how to tell when the flash menu is done loading.

Sending you both the code now.
« Last Edit: November 02, 2005, 04:51:30 PM by Skar »
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Spriggan

  • Administrator
  • Level 78
  • *****
  • Posts: 10582
  • Fell Points: 31
  • Yes, I am this awesome
    • View Profile
    • Legacies Lost
Re: Yet Another code question posed to the gurus
« Reply #10 on: November 02, 2005, 04:51:32 PM »
I'm not much of a JS man, though I have seen people place their <script> tags at the end of the page before the </html> to solve loading problems.
Screw it, I'm buying crayons and paper. I can imagineer my own adventures! Wheeee!

Chuck Norris is the reason Waldo is hiding.


Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #11 on: November 02, 2005, 05:01:36 PM »
Would that help if the code was trying to talk to a .swf file?  Or would the browser hit the script while still loading the .swf in the background?
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Eric James Stone

  • Level 12
  • *****
  • Posts: 519
  • Fell Points: 0
    • View Profile
    • Eric James Stone's Website
Re: Yet Another code question posed to the gurus
« Reply #12 on: November 02, 2005, 06:14:27 PM »
OK, so I think you're right that it's executing before the swf file has loaded.

I'm afraid I don't know enough about JS interaction with Flash animations to be of help.
Eric James Stone
Nebula Award Nominated Author
Read my serialized novel Unforgettable for free online.

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #13 on: November 02, 2005, 06:40:34 PM »
Thanks for looking at it anyway.  I appreciate it.

The maddening thing is that all the forums are filled with workarounds so that you can fire events BEFORE the whole page is loaded.  Everyone talks as though the onLoad event happens after all content, including images, is loaded and nobody but me wants it to happen the way it's suposed to.  Arrrrrgh.

Some days my avatar feels more apropos than others.
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch

Skar

  • Moderator
  • Level 54
  • *****
  • Posts: 3979
  • Fell Points: 7
    • View Profile
Re: Yet Another code question posed to the gurus
« Reply #14 on: November 03, 2005, 01:27:18 PM »
FYI

I ended up having to bypass the whole problem by having the flash movie itself test whether it was all loaded and send a command to javascript to run the SetMenu function when it was.  

Works.
"Skar is the kind of bird who, when you try to kill him with a stone, uses it, and the other bird, to take vengeance on you in a swirling melee of death."

-Fellfrosch