Get the mouse position on the page and right-click the event

Source: Internet
Author: User

JS notation
document.getElementById ("Youji"). oncontextmenu=youjievent;//specify this element to bind right-click events
function Youjievent () {//The menu is displayed when the mouse is right-clicked
alert (item.name);
Return false;//the right-click effect of the shielded Web page itself
}

jquery notation
$ (function () {
$ (' #youji '). MouseDown (function (e) {
if (e.which==1) {
Alert ("This is the left-click event");

}else if (E.which = = 2) {
Alert ("This is a mid-strike event");
}else{
Alert ("This is the right-click event");
Return false;//block the right click event of the webpage itself
}
});
})

Right-click area of the mouse
<div id= "Youji" style= "width:200px; height:200px; Background-color: #1621E5 "></div>


Gets the XY coordinates of the mouse when clicked on the page
JS notation
var x, y;
function mouseposition (EV) {
if (Ev.pagex | | ev.pagey) {
return {x:ev.pagex, y:ev.pagey};
}
return {
X:ev.clientx + Document.body.scrollleft-document.body.clientleft,
Y:ev.clienty + document.body.scrolltop-document.body.clienttop
};
}
function MouseMove (EV) {
EV = EV | | window.event;
var mousepos = mouseposition (EV);
x = mousepos.x;
y = mousepos.y;
}
Document.onmousedown = MouseMove;

Get the mouse position on the page and right-click the event

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.