document.onclick vs window.onclick

Nazmul picture Nazmul · Mar 5, 2010 · Viewed 47.5k times · Source

Is there any difference between

document.onclick

and

window.onclick

event?

Thanks.

Answer

Justin Ethier picture Justin Ethier · Mar 5, 2010

The JavaScript Window object is the highest level JavaScript object which corresponds to the web browser window.

The document object is the container for all HTML HEAD and BODY objects associated within the HTML tags of an HTML document. This could correspond to the top-most window, or an iframe within the window.

Update

After a quick test there really is no difference between the two. However, as others have said, window.onclick did not work when tested in IE8. So apparently the bottom line is that document.onclick is the preferred choice.