Click to See Complete Forum and Search --> : window.onclick


jasonli
July 20th, 2007, 11:49 AM
In VS2005 asp.net project, I inserted a html page, and set it as start page. the code of html page is:

<html>
<head>

<title>onclick test</title>

<script type="text/javascript">

window.onclick = clickPage;

function clickPage()
{
alert("click event detected!");
}
</script>
</head>

<body>
<p>click and release the LH mouse button on this page.</p>
</body>
</html>

When I run it, click somewhere in webpage, the alert message doesn't show up. Why? Did I miss something?

andreasblixt
July 20th, 2007, 01:52 PM
Use this instead:
function clickPage() {
alert("Document was clicked.");
}

document.onclick = clickPage;

The document object is more cross-browser compatible.

jasonli
July 20th, 2007, 05:24 PM
Thank you very much. It's working.