window.onload = function () { var menu = document.getElementById("right_button_menu"); document.oncontextmenu = function (e) { return false; } function click(e) { var e=e||event; if (e.which == 2||e.button==4){//中间滚轮键 hide_menu(menu); return false; } else if(e.which==3||e.button==2) { //右键 x = e.clientX;y=e.clientY; var l = document.body.scrollLeft>0?document.body.scrollLeft:document.documentElement.scrollLeft; var t = document.body.scrollTop>0?document.body.scrollTop:document.documentElement.scrollTop; document.title = "x"+(x+l) + "y" + (y+t); show_menu(menu,x+l,y+t); } else if(e.which==1||e.button==1){ //左键 setTimeout(function () { hide_menu(menu) },100) } } document.onmousedown = click; function show_menu(obj,left,top) { obj.style.left = left + "px"; obj.style.top = top + "px"; obj.style.display = 'block'; } function hide_menu(obj) { obj.style.display='none'; } }