Moodle
  1. Moodle
  2. MDL-4346

javascript defer attribute causes error in IE

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.3, 1.9.1
    • Fix Version/s: 1.8.7, 1.9.3
    • Component/s: General
    • Labels:
      None
    • Environment:
      Windows XP
    • Affected Branches:
      MOODLE_15_STABLE, MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE
    • Rank:
      27541

      Description

      in lib/javascript.php:

      <script language="JavaScript" type="text/javascript" defer="defer">

      The "defer" causes Internet Explorer to defer processing of the openpopup() {} function definition to after the page has finished loading. This causes an error on pages where openpopup() is called before the page has finished loading, eg. when loading the messages popup window after logging in.

      This can be fixed by changing the line to:

      <script language="JavaScript" type="text/javascript">

      The problem does not effect Firefox.

      1. patch-4346-defer.txt
        0.8 kB
        Mathieu Petit-Clair

        Issue Links

          Activity

          Hide
          Martin Dougiamas added a comment -

          From Gustav Delius (gwd2 at york.ac.uk) Sunday, 11 December 2005, 07:31 PM:

          I had a similar problem on a site using the formal white theme. However looking at the source of the file in my case I can see that the openpopup function IS defined, however in a javascript environment that has defer=defer. What helped in my case (and I have no idea why) was to take out the defer=defer.

          Show
          Martin Dougiamas added a comment - From Gustav Delius (gwd2 at york.ac.uk) Sunday, 11 December 2005, 07:31 PM: I had a similar problem on a site using the formal white theme. However looking at the source of the file in my case I can see that the openpopup function IS defined, however in a javascript environment that has defer=defer. What helped in my case (and I have no idea why) was to take out the defer=defer.
          Hide
          Richard Rode added a comment -

          It's only IE (6.0) that doesn't accept scripts with defer. the popups work fine in firefox.

          Show
          Richard Rode added a comment - It's only IE (6.0) that doesn't accept scripts with defer. the popups work fine in firefox.
          Hide
          Ashley Holman added a comment -

          This happens in both IE6 and IE7. The problem also effects the automatic popup of the messaging window upon login. IE gets a javascript error instead of popping up the messages window.

          I removed the 'defer=defer' and this fixed the problem.

          The 'defer' attribute is meant to optimise page loading time by telling the browser that it can "defer" processing the javascript until the page is fully loaded. This works fine when the openpopup() call is part of an onClick event after the page has finished loading. The problem occurs when the openpopup() function is called from within the body before the page is fully loaded, ie. in the cases where the popup is meant to load instantly like with the messaging window. The processing of 'function openpopup() {}' is deferred so trying to call it prematurely results in a javascript error.

          This bug describes the problem and fix: http://tracker.moodle.org/browse/MDL-6482
          Here's another issue that may be the same problem: http://tracker.moodle.org/browse/MDL-13512

          Show
          Ashley Holman added a comment - This happens in both IE6 and IE7. The problem also effects the automatic popup of the messaging window upon login. IE gets a javascript error instead of popping up the messages window. I removed the 'defer=defer' and this fixed the problem. The 'defer' attribute is meant to optimise page loading time by telling the browser that it can "defer" processing the javascript until the page is fully loaded. This works fine when the openpopup() call is part of an onClick event after the page has finished loading. The problem occurs when the openpopup() function is called from within the body before the page is fully loaded, ie. in the cases where the popup is meant to load instantly like with the messaging window. The processing of 'function openpopup() {}' is deferred so trying to call it prematurely results in a javascript error. This bug describes the problem and fix: http://tracker.moodle.org/browse/MDL-6482 Here's another issue that may be the same problem: http://tracker.moodle.org/browse/MDL-13512
          Hide
          Ashley Holman added a comment -

          updated summary/description to more accurately describe the problem

          Show
          Ashley Holman added a comment - updated summary/description to more accurately describe the problem
          Hide
          Martin Dougiamas added a comment -

          As I recall the defer was added to make editors work (could be wrong). As such this suggested change might break other things. Mat can you look into this please?

          Show
          Martin Dougiamas added a comment - As I recall the defer was added to make editors work (could be wrong). As such this suggested change might break other things. Mat can you look into this please?
          Hide
          Mathieu Petit-Clair added a comment -

          I think the good way to solve this would be (as suggested) to remove the "defer" and instead call the javascript at the end of the page. The call to get the popup window for messages should probably be done there too (though just a bit later). This could be done in footer.html, just before </body>. We might need something like this for the new editor system...

          I'll have a better look later.

          Show
          Mathieu Petit-Clair added a comment - I think the good way to solve this would be (as suggested) to remove the "defer" and instead call the javascript at the end of the page. The call to get the popup window for messages should probably be done there too (though just a bit later). This could be done in footer.html, just before </body>. We might need something like this for the new editor system... I'll have a better look later.
          Hide
          Mathieu Petit-Clair added a comment -

          Removing defer would solve this problem ... but defer was introduced in 2005 by defacer, to fix a bug in IE. I have the feeling this bug might have been fixed in the themes since then, but... the commit wasn't linked to anything in the tracker, so it's hard to say.

          Relevant cvs entries:
          http://cvs.moodle.org/moodle/lib/javascript.php?r1=1.21&r2=1.22
          http://cvs.moodle.org/moodle/lib/javascript-static.js?r1=1.5&r2=1.6

          I don't know which IE bug this fixes, maybe somebody can tell me if it's still needed...

          Show
          Mathieu Petit-Clair added a comment - Removing defer would solve this problem ... but defer was introduced in 2005 by defacer, to fix a bug in IE. I have the feeling this bug might have been fixed in the themes since then, but... the commit wasn't linked to anything in the tracker, so it's hard to say. Relevant cvs entries: http://cvs.moodle.org/moodle/lib/javascript.php?r1=1.21&r2=1.22 http://cvs.moodle.org/moodle/lib/javascript-static.js?r1=1.5&r2=1.6 I don't know which IE bug this fixes, maybe somebody can tell me if it's still needed...
          Hide
          Ashley Holman added a comment -

          I'm not sure whether fix_column_widths() is still needed or not, but it looks like it might have been "deferred" so that the left-column and right-column exist before it is executed.

          So we could keep that part deferred and have the rest in a separate <script> tag, eg.

          <script type="text/javascript" defer="defer">
          setTimeout('fix_column_widths()', 20);
          </script>
          <script type="text/javascript">
          function openpopup ........
          .....
          </script>

          Show
          Ashley Holman added a comment - I'm not sure whether fix_column_widths() is still needed or not, but it looks like it might have been "deferred" so that the left-column and right-column exist before it is executed. So we could keep that part deferred and have the rest in a separate <script> tag, eg. <script type="text/javascript" defer="defer"> setTimeout('fix_column_widths()', 20); </script> <script type="text/javascript"> function openpopup ........ ..... </script>
          Hide
          Mathieu Petit-Clair added a comment -

          Committed to 1.8, 1.9 and head, thanks.

          Show
          Mathieu Petit-Clair added a comment - Committed to 1.8, 1.9 and head, thanks.
          Hide
          Dongsheng Cai added a comment -

          Closing, thanks

          Show
          Dongsheng Cai added a comment - Closing, thanks

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: