Assign the "onclick" event to the window object:
This example demonstrates how to assign an "onclick" event to the window object.
Click anywhere in this window to change the background color of body.
<!DOCTYPE html> <html> <body> <script> window.onclick = myFunction;//from w w w . jav a2 s . com function myFunction() { document.getElementsByTagName("BODY")[0].style.backgroundColor = "yellow"; } </script> </body> </html>