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

See Also:
Latest Commit:
Version Fixed In:


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!