PDA

View Full Version : توابع تشخیص راست کلیک و کلیک چپ چیه و چطوری استفاده می شن؟



mehdin69
سه شنبه 30 آذر 1389, 22:04 عصر
سلام دوستان با چه تابعی می تونم event right click یا left click ماوس روکنترل کنم؟؟؟:متفکر:
اگهمی شه مثالی بزنید ممنون می شم
مرسی
:قلب:

hossin.esm
چهارشنبه 01 دی 1389, 14:27 عصر
<button onclick="test()">click</button>
<button onmousedown="alertBut(event)">right click</button>
<button onclick="alert('test');">test</button>

<SCRIPT language="javascript">
function test()
{
alert('click');
}
function alertBut( e, evElement ) {

if( !e ) {
if( window.event ) {
//Internet Explorer
e = window.event;
} else {
//total failure, we have no way of referencing the event
return;
}
}
if( typeof( e.which ) == 'number' ) {
//Netscape compatible
e = e.which;
if(e==1)
{
alert('left click');
}
else if(e==2)
{
alert('middle click');
}
else if(e==3)
{
alert('right click');
}

} else if( typeof( e.button ) == 'number' ) {
//DOM
e = e.button;
if(e==1)
{
alert('left click');
}
else if(e==4)
{
alert('middle click');
}
else if(e==2)
{
alert('right click');
}

} else {
//total failure, we have no way of obtaining the button
return;
}
if( !evElement ) { evElement = this; }
/* 'this' will exist if I have used object.onEventName = alertBut;
If I have passed evElement from the onmouseup attribute,
'this' will refer to window */
window.alert( evElement + ' was clicked with button ' + e );
}
</script>
</SCRIPT >