Search code examples
javascriptdrupal-6

In a Drupal message box, why is the close button not working in Chrome?


This is only happening in Chrome. IE and Firefox work just fine. In the console I get the error: Uncaught TypeError: object is not a function enter image description here

It is saying the error is here but I don't even know where this is:

(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {onclose()
};}}}})

Solution

  • You have some sort of conflict with that function name.

    Try:

    window.onclose();
    

    Or even better:

    document.getElementById("aerror").addEventListener('click', function() {
        alert('Hello world');
    }, false);
    

    You should always use event listeners: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener#Why_use_addEventListener.3F