I would like to intercept all click events on my document

Z

zoltix

Hi,

I am beginner in JavaScript. I would like to intercept all click
events on my document. I use this function for that
document.onmousedown=click;. It works well. But I would like to
continue the execution code on a other button or anything else.


Example
1) Click anywhere intercept click->Execute the code in function click().
2) Click on a link…. intercept click -> Execute the code in function
click() ->Load the link(http://test.html)
3) Click on a button… intercept click-> Execute the code in function
click() ->Execute the code for the button(submit, or other javascript)


Thank a lot for your help…



function click() {
if (event.button==1) {
alert(“Test event”)
//execute before….ex close all div
}
//Here continue code
}
 
M

McKirahan

zoltix said:
Hi,

I am beginner in JavaScript. I would like to intercept all click
events on my document. I use this function for that
document.onmousedown=click;. It works well. But I would like to
continue the execution code on a other button or anything else.


Example
1) Click anywhere intercept click->Execute the code in function click().
2) Click on a link…. intercept click -> Execute the code in function
click() ->Load the link(http://test.html)
3) Click on a button… intercept click-> Execute the code in function
click() ->Execute the code for the button(submit, or other javascript)


Thank a lot for your help…



function click() {
if (event.button==1) {
alert(“Test event”)
//execute before….ex close all div
}
//Here continue code
}

Is this what you're looking for?

<html>
<head>
<title>clicked.htm</title>
<script type="text/javascript">
function clicked(what) {
alert(what);
}
</script>
</head>
<body onclick="clicked(0)">
<a href="http://www.google.com/options/index.html?1" target="_blank"
onclick="return clicked(1)">Google</a>
<br><br>
<form action="http://www.google.com/options/index.html?2" method="get"
target="_blank">
<input type="button" value="Button" onclick="clicked(2)">
<input type="submit" value="Submit" onclick="clicked(3)">
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top