Bug 127236 - window.onload inconsistencies with simple function onload()
Summary: window.onload inconsistencies with simple function onload()
Status: RESOLVED WORKSFORME
Alias: None
Product: konqueror
Classification: Applications
Component: kjs (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-13 10:03 UTC by jordan.osete
Modified: 2023-01-12 05:16 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Test files to prove this works OK. (442 bytes, text/plain)
2007-05-11 22:58 UTC, keith
Details
javascript containing the onPageLoad function (456 bytes, text/plain)
2007-05-11 23:00 UTC, keith
Details
seperate javascript file to use the onPageLoad function (220 bytes, text/plain)
2007-05-11 23:01 UTC, keith
Details

Note You need to log in before you can comment on or make changes to this bug.
Description jordan.osete 2006-05-13 10:03:48 UTC
Version:           3.5.2 (using KDE 3.5.2, Debian Package 4:3.5.2-2+b1 (testing/unstable))
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.15-1-k7

May be related to bug 27988 http://bugs.kde.org/show_bug.cgi?id=27988

Normally, creating a function in the global scope should create a child of the window object. Thus, you can assign an onload event handler to the windows object just by doing this (currently only FF does this correctly):
  function onload(){alert('onload called')}
Konqueror doesn't understand it. Worse, if you first assign an onload with window.onload=function(){...}, it will call none of the two:

  onload=function(){alert("onload1");}
  //should display an alert
  function onload (){alert('onload2')};
  alert("This is the onload function registered: \n\n"+window.onload);

Simple testcase: http://ministeyr.free.fr/testcases/test_onload.htm

Then it will display that the onload function registered is the first one, but call neither when the page is loaded. Note that Firefox, Opera and Konqueror all behave in a wrong way here.
Comment 1 keith 2007-04-03 23:09:34 UTC
I have the same problem as well on FC6 with Konqueror 3.5.6 & KDE 3.5.6

The following piece of javascript code does not get executed after the window.onload event fires:

function onPageLoad(newAction) {
  if ('function' == typeof window.onload) {
    var prevActions = window.onload;
    window.onload = function() {
    prevActions();
    newAction();
    }
  }
  else {
    window.onload = newAction;
  }
}

adding a function to be executed with this code after the onload event fires does not work.

The above anonymous function assigned to the window.onload property should allow several functions to be queued for running after the page loads. This works OK in FF 1.5.0.10 - nothing happens at all in Konqueror.

onPageLoad(firstFunc);
onPageLoad(secondFunc);
onPageLoad(thirdFunc);

should allow those three functions to executed in that order after the page has loaded. Obviously the functions need to exist in a javascript file used by the page. Sorry I don't have a URL to point you to just now. But you can test this out by copying the above function to your own JS file locally.
Comment 2 keith 2007-05-11 22:58:56 UTC
Created attachment 20540 [details]
Test files to prove this works OK.

just copy the three files into a directory under your webserver root, and load
onPageLoad.php into Konqueror, Firefox, etc.
Comment 3 keith 2007-05-11 23:00:18 UTC
Created attachment 20541 [details]
javascript containing the onPageLoad function
Comment 4 keith 2007-05-11 23:01:02 UTC
Created attachment 20542 [details]
seperate javascript file to use the onPageLoad function
Comment 5 keith 2007-05-11 23:09:58 UTC
The above attachments prove that the window.onload event is actually working correctly in Konqueror. I t also works OK in Firefox, IE 7.0, 6.0, 5.5 & 5.0.

The problem appears to be using console.log messages in a javascript function for Firefox Firebug debugger. Having removed those console.log messages all works well now!
Comment 6 Maksim Orlovich 2007-05-11 23:26:01 UTC
For first testcase:
Firefox's handling of function declarations is incredibly broken, and is not ECMA 262-3 compliant. Konqueror's is correct in this case (but buggy in some others), as are those in IE and Opera.

If you say:

function onload()
{
}

You are /declaring/ onload to be a local variable, which is initialized to the function as you start executing the scope. Hence, any assignment of window.onload merely changes the local value. (And locals generally 
shadow the dynamic properties in window object, though perhaps this is a special case). So when you say:

onload = function() {}

function onload() { ... }

the 'function onload' stuff gets handled /first/ in standards-compliant browsers. What you want to do is simply use 

onload = function () {} consistently, and it'll work just fine everywhere.
(Since Mozilla brokenly interpreters function onload() as onload = function() ..)

Re: comment #5 and on: so it's fine for your stuff?

Comment 7 Jonas Vejlin 2009-04-05 08:20:06 UTC
do you still have this problem in konq 4?
Comment 8 keith 2009-04-20 20:37:31 UTC
I've not tested this yet in K4 yet. Not doing any JS coding right now.
Comment 9 Andrew Crouthamel 2018-11-02 23:06:31 UTC
Dear Bug Submitter,

This bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version? I am setting the status to NEEDSINFO pending your response, please change the Status back to REPORTED when you respond.

Thank you for helping us make KDE software even better for everyone!
Comment 10 Andrew Crouthamel 2018-11-16 05:36:58 UTC
Dear Bug Submitter,

This is a reminder that this bug has been stagnant for a long time. Could you help us out and re-test if the bug is valid in the latest version?

Thank you for helping us make KDE software even better for everyone!
Comment 11 Justin Zobel 2022-12-13 02:54:22 UTC
Thank you for reporting this issue in KDE software. As it was reported on an older version, can we please ask you to see if you cazn reproduce the issue with a more recent software version?  
  
If you can confirm this issue still exists in a recent version, please change the version field and the status to "REPORTED" when replying. Thank you!
Comment 12 Bug Janitor Service 2022-12-28 05:23:10 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 13 Bug Janitor Service 2023-01-12 05:16:10 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!