Search code examples
javascriptinternet-explorerdom-events

"Error type null or not an object" in Internet Explorer


My code works in Firefox but I am having trouble with Internet Explorer. When it executes, I get an error and the program doesn't execute right. The description says:

clientX is null or not an object.

var cursorLocation = new function(){
this.x = 0;
this.y = 0;
//This function is called onmousemove to update the stored position
this.update = function(e){
    var w = window, b = document.body;
    this.x =  e.clientX + (w.scrollX || b.scrollLeft || b.parentNode.scrollLeft || 0);
    this.y = e.clientY + (w.scrollY || b.scrollTop || b.parentNode.scrollTop || 0);
}}      document.onmousemove=function(e){ cursorLocation.update(e); };

Solution

  • You should not do new function(){...} in javascript.

    There is your error.


    You should be doing something like this:

    var someFunction = function(){....};
    
    var someVariable = new someFunction();