tags:

views:

259

answers:

4

I have a page and use window.addEvent('load', function() { alert('test'); }), but the browser never displays the alert. There are no JavaScript errors on the page that prevent this from running.

What might be happening? Is it possible that the page already loaded so the 'load' even doesn't fire?

A: 

You must have an error or something. Look: http://mootools.net/shell/vcBsn/

Also, if possible post a link to your test-case.

Oskar Krawczyk
+1  A: 

You might want to try using the 'domready' event. Once the DOM is loaded in the window, the function would be executed.

window.addEvent('domready', function(evt) {
   alert('dom loaded!);
});
Pat
A: 

Check in firebug if all ur scripts are getting loaded (due to path error script might not be getting loaded) Also include the mootools scripts first then ur custom scripts.

Undefined
A: 

In IE7, the following code will not do if the html page has little content

window.addEvent("domready", function() {
    $(window).addEvents( {
        "load" : loadListener
    });
    function loadListener() {
        window.alert("Window has loaded!");
    }
});

And these code shoud be changed like this:

window.addEvents( {
    "load" : function() {
        window.alert("Window has loaded!");
    },
    "domready" : function() {
        /* do something */
    }
});

Is it the solution for you problem?

FuDesign2008