Opened 15 years ago

Closed 14 years ago

#1472 closed defect (fixed)

Get rid of Javascript elements that use the 'defer' attribute

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: major Milestone: BASE 2.16
Component: web Version:
Keywords: Cc:

Description

We should at least investigate the behavior of such scripts and make sure that they really work as expected. For background information see #1453 and http://peter.michaux.ca/articles/the-window-onload-problem-still

Change History (10)

comment:1 by Nicklas Nordborg, 15 years ago

A quick search found 'defer' in the following places:

  • Taglibs: Body, Table, TabControl
  • JSP scripts: views/experiments/explorer/view/view.jsp

comment:2 by Nicklas Nordborg, 15 years ago

Milestone: BASE 2.16

comment:3 by Nicklas Nordborg, 15 years ago

Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

Since this is likely to have global impact I'll fix this early to increase the chance to solve problems.

comment:4 by Nicklas Nordborg, 15 years ago

The simplest solution to this problem is to add event handlers that reacts to the 'onload' event. Since this is somewhat browser dependent I have implemented a helper function for this. So, instead of:

<script language="JavaScript" defer="defer">
  // script code here
</script>

do:

<script language="JavaScript" >
function init()
{
  // script code here
}
Main.onLoad(init);
</script>

or using an anonymous function:

<script language="JavaScript" >
Main.onLoad(function() 
  {
  // script code here
  }
);
</script>

comment:5 by Nicklas Nordborg, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [5322]) Fixes #1472: Get rid of Javascript elements that use the 'defer' attribute

comment:6 by Nicklas Nordborg, 14 years ago

Resolution: fixed
Status: closedreopened

The current solution doesn't work in so well in IE, and actually not in Firefox either but it is not as bad in FF as in IE.

The problem is the execution order of the init() and switchTab() methods. The last comment in #1453 noted that before this change switchTab() was executed before init(), but that the desired execution order was the opposite order.

It turns out that there is a problem with executing the init() method first. This is because the init() method often contains code that sets the focus to the first field in the form. For example:

frm.name.focus();
frm.name.select();

The trouble here is that the form is not visible and an invisible input field can't have the focus. In Firefox the calls to set the focus are simply ignored and the only result is that no input field has the focus when the page has been fully loaded and initialized.

In IE the browser throws and error and stops executing the javascript code. Typically this means that an empty page is displayed with no "active" tab. It is possible to click a tab to show it. But this is just a minor annoyance. The real problem is that in some cases the init() contains a lot more code. When this code isn't executed there may be all kinds of unexpected problems with the page.

So, it seems like we should keep the old execution order were switchTab() is executed first and init() last. The simplest way is to reverse the execution order among the registered methods and hope that it doesn't break anything else.

comment:7 by Nicklas Nordborg, 14 years ago

Status: reopenednew

comment:8 by Nicklas Nordborg, 14 years ago

Status: newassigned

comment:9 by Nicklas Nordborg, 14 years ago

(In [5365]) References #1472: Get rid of Javascript elements that use the 'defer' attribute

Reverses the order of the function calls and added try/catch to not let one bad-behaving function stop everything.

comment:10 by Nicklas Nordborg, 14 years ago

Resolution: fixed
Status: assignedclosed

Closing this again. Have not seen any strange things for some time now.

Note: See TracTickets for help on using tickets.