#4 ✓resolved
David Tarico

[Dup Trac #10100] Error in "pointer" function on IE

Reported by David Tarico | April 16th, 2008 @ 09:08 PM | in 1.6.0.3

I recently upgraded to prototype version 1.6.0.2, and now I'm randomly getting javascript errors when pages load in IE6 and IE7. The errors seem to happen more often after just having cleared the browser cache.

The errors say "Object required", and is occurring in the Element.Methods.pointer function.

The line of code causing the problem is:

        x: event.pageX || (event.clientX +
          (document.documentElement.scrollLeft || document.body.scrollLeft)),

In my case, document.documentElement.scrollLeft is 0, which evaluates to false, so it tries to evaluate document.body.scrollLeft but document.body is null and throws the error.

The event.type = "mousemove"

I'm guessing the pointer function needs to guard against "mousemove" events that fire before the page has finished loading.

Comments and changes to this ticket

  • Andrew Dupont

    Andrew Dupont April 18th, 2008 @ 04:34 AM

    • State changed from “new” to “open”

    We'll take a look; thanks. In the meantime, the workaround would be not to assign any mousemove events before the dom:loaded event.

  • John-David Dalton

    John-David Dalton April 15th, 2008 @ 04:03 AM

    • Title changed from “Error in "pointer" function on IE” to “[Dup Trac #10100] Error in "pointer" function on IE”

    duplicate of http://dev.rubyonrails.org/ticke....

    #10100 has patches and tests (the patches are not perfect but pretty close :P)

  • Tobie Langel

    Tobie Langel April 17th, 2008 @ 09:40 AM

    • State changed from “open” to “bug_report”
    • Milestone set to 1.6.0.3
  • Tobie Langel

    Tobie Langel April 18th, 2008 @ 01:14 PM

    • State changed from “bug_report” to “bug”
  • Juriy Zaytsev

    Juriy Zaytsev April 19th, 2008 @ 05:58 PM

    The #10100 looks good to me. An alternative approach would be to create dummy properties when original are not available:

    
    var docElement = document.documentElement,
        body = document.body || { scrollLeft: 0, scrollTop: 0 };
    
    return {
      x: event.pageX || (event.clientX + 
        (docElement.scrollLeft || body.scrollLeft) -
        (docElement.clientLeft || 0)),
      y: event.pageY || (event.clientY + 
        (docElement.scrollTop || body.scrollTop) -
        (docElement.clientTop || 0))
    };
    
    
  • Juriy Zaytsev

    Juriy Zaytsev April 19th, 2008 @ 05:58 PM

    • Assigned user set to “Juriy Zaytsev”
  • John-David Dalton

    John-David Dalton April 23rd, 2008 @ 08:51 PM

    to test start moving your mouse an dkeep pressing F5 to refresh the page. Without the fix you should get an error. With the fix all works well.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stric...">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title>Test</title>
    <script type="text/javascript" src="prototype.js"></script>
    <script>
      Event.observe(document.documentElement, 'mousemove', function(event){
          window.status = event.pointer().x;
      });
    </script>
    
    </head>
    <body>
    <img id="img" src="http://emc.moxiecode.com/slow.php" />
    </body>
    </html>
    

    I have applied this patch to my fork:

    http://github.com/jdalton/protot...

  • Richard Quadling

    Richard Quadling April 24th, 2008 @ 01:18 PM

    Just to make the point, the error is not specific to mousemove, but any event being fired (including custom events unrelated to DOM) before the DOM is loaded.

    document.observe('raq:test', function() { alert('Boing!'); } );

    document.fire('raq:test');

    For watching DOM events, you should watch for dom:loaded first ...

    document.observe('dom:loaded', function() {

    // Now you can observe the mousemoves.

    });

  • John-David Dalton

    John-David Dalton April 24th, 2008 @ 02:46 PM

    Ya, trying to access dom elements before they are loaded is gonna cause you some issues :P

    But I should point out that this works :)

    <script type="text/javascript" src="prototype.js"></script>
    <script>
    
    document.observe('raq:test', function() { alert('Boing!'); } );
    document.fire('raq:test');
    </script>
    

    Now if it was attached to another dom element it would probably error out.

  • Richard Quadling

    Richard Quadling April 24th, 2008 @ 03:00 PM

    Take a look at my proof at http://dev.rubyonrails.org/attac...

    This is using Prototype 1.6.0.

    Change the prototype source to

    And you still get the problem.

    Line 3788.

    Firing events currently requires a body. And in IE, there is no body until the dom is loaded. EVEN IF YOU ARE FIRING NON DOM EVENTS.

    Richard.

  • Richard Quadling

    Richard Quadling April 24th, 2008 @ 03:02 PM

    Uh? The script tag was removed (ain't they heard of entity encoding?)

    http: // prototypejs.org / assets / 2008 / 1 / 25 / prototype-1.6.0.2.js

    Try the testfire.html with this JS source (spaces added to stop LHA chopping it.

  • John-David Dalton

    John-David Dalton April 24th, 2008 @ 03:14 PM

    Sorry Richard, I was testing with the fix already applied :P

    For future reference use http://www.lighthouseapp.com/hel... for info on how to format text in LH.

  • Richard Quadling

    Richard Quadling April 24th, 2008 @ 03:21 PM

    Ha. And thanks for the formatting tip.

  • GitHub Robot

    GitHub Robot April 24th, 2008 @ 09:06 PM

    • State changed from “bug” to “resolved”

    (from [92c32e7d6d5324386f37b59554e5c4fe889dafc7]) Fix an issue with calling Event.pointer before the DOM is loaded. (kangax, jddalton) [#4 state:resolved]

    (cherry picked from commit af704e7b2280eb4a9ef26a54662427bfc11cb729)

    http://github.com/sstephenson/pr...

  • Adam Ingram-Goble

    Adam Ingram-Goble September 10th, 2008 @ 04:18 PM

    • Tag set to events, patched

    This patch doesn't seem to actually address the problem of the object sometimes not being available. Both documentElement and body seem to be unavailable when this section of code is triggered at the end of the load in IE 6 and IE 7.

    My project resolved this by changing the pointer function at line 3787 of prototype 1.6.0.2 to the following

    
        pointer: function(event) {
          return {
            x: event.pageX || (event.clientX + ((document.documentElement ? document.documentElement.scrollLeft : 0) || (document.body ? document.body.scrollLeft : 0))),
            y: event.pageY || (event.clientY + ((document.documentElement ? document.documentElement.scrollTop : 0) || (document.body ? document.body.scrollTop : 0)))
          };
        },
    

    It seems like the patch in #10100 is also fixing some of the math with an additional offset, but the code does not actually address the document..scroll problem where body or documentElement is undefined.

  • Adam Ingram-Goble

    Adam Ingram-Goble September 10th, 2008 @ 04:22 PM

    • Tag changed from events, patched to events, ie, needs_patch

    Sorry, I should have tagged this as something else...

  • John-David Dalton

    John-David Dalton September 10th, 2008 @ 04:30 PM

    @Adam - could you please provide a failing test case (small snippet that demonstrates a failure). I have not seen a situation in which document.documentElement isn't available.

  • Juriy Zaytsev

    Juriy Zaytsev September 10th, 2008 @ 05:02 PM

    John, I think document.documentElement is not available in QuirksMode in IE (and so document.body is behaving as document.documentElement)

  • John-David Dalton

    John-David Dalton September 10th, 2008 @ 05:27 PM

    Juriy I ran a quick test:

    
    <html>
    <head>
    <title>Default</title>
    
    <script type="text/javascript">
      alert(document.compatMode+'; '+document.documentElement.nodeName);
    </script>
    
    </head>
    <body>
    
    </body>
    </html>
    

    alerts -> BackCompat; HTML (so in Quirksmode IE5.5,6,7 see HTML has documentElement);

  • skaue

    skaue September 10th, 2008 @ 08:12 PM

    I've attached a trace doing with Visual Studio 2008 script debugger. Running prototype (1.6.0.2) and extjs. Loading a page, then clicking to load another page. The event that fails seems to be the "unload". Please see attached screenshots. Hope it can help to trace it down. Let me know if you need more info.

  • skaue

    skaue September 10th, 2008 @ 08:18 PM

    I might be mistaken, but this can be some other error. It refers to line 3777 saying onbject is undefined. The object that is null is "node".

    Please disregard my screendumps if this is related to some other error.

  • skaue

    skaue September 10th, 2008 @ 09:02 PM

    I applied this patch and now the errors are gone... However, I'm not sure what other problems might appear:

    
         isRightClick:  function(event) { return isButton(event, 2) },
    
         element: function(event) {
    -      var node = Event.extend(event).target;
    +      var node = Event.extend(event).target; if(node==null) return null;
           return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);
         },
    

    node was null, and remained null after being extended. I don't know what this code is intended to do, so the experts must validate this.

  • John-David Dalton

    John-David Dalton September 10th, 2008 @ 10:12 PM

    that error has been fixed in the trunk

  • skaue

    skaue September 10th, 2008 @ 11:10 PM

    Ok... then I have a real stupid question... where is the trunk? is it here: http://github.com/sstephenson/pr...

    /me looks down ashamed

  • John-David Dalton

    John-David Dalton September 10th, 2008 @ 11:13 PM

    *no worries ya thats the trunk (its going through some reorganization but the fix should be in the events.js)

  • skaue

    skaue September 11th, 2008 @ 03:39 PM

    (sorry, I know this is completely off topic) replacing the events.js section in the complete prototype.js introduced other errors... how can I get a complete prototype.js from the trunk without installing various sourcecontrol+compiler programs...

  • John-David Dalton

    John-David Dalton September 11th, 2008 @ 04:10 PM

    @skaue I would wait until Oct 1-3 or so Prototype should be releasing a stable 1.6.0.3 around then.

  • Richard Quadling
  • skaue

    skaue June 29th, 2009 @ 11:41 AM

    beautiful. Can someone plz delete those posts before google crawls them and give this stupid spammer what he needs... :-/

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from events, ie, needs_patch to events, ie, missing:patch

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from events, ie, missing:patch to events, ie, needs:patch

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:55 AM

    • Tag changed from events, ie, needs:patch to ie, needs:patch, section:dom

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:55 AM

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 04:05 AM

    • Tag changed from ie, needs:patch, section:dom to needs:patch, section:dom

    [not-tagged:"ie" not-tagged:"ie6" not-tagged:"ie7" not-tagged:"ie8" bulk edit command]

  • jeux4banat

    jeux4banat March 17th, 2016 @ 08:17 PM

    العاب الطبخ وخصوصا لعبة طبخ كيك انصحكم بتجريبها للانها الافضل على الاطلاق يمكنكم اللعب فيها بدون تحميل

  • jeuxnewbanat

    jeuxnewbanat March 18th, 2016 @ 01:45 AM

    jeuxnewbanat موقع يضم مجموعة من العاب تلبيس بنات جديدة ورائعة جربها مجانا

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Attachments

Referenced by

Pages