Object [object DOMWindow] has no method ‘attachEvent’

This error occurs when trying bind an event, using window.attachEvent as a function, which only works in Internet Explorer.

Your code might look something like this:

var myFunction = function(){
  alert("foo");
}

window.attachEvent("onclick", myFunction);

To fix this, use the following code (remember to remove “on” from “onclick” etc):

var myFunction = function(){
  alert("foo");
}

window.addEventListener("click", myFunction);