Mouse Buttons on different Browsers
2010-06-11 11:41
211 查看
Deals with the fact that mouse buttons are referenced in different ways
by different browsers.
原帖地址: http://snipplr.com/view/275/mouse-buttons-on-different-browsers/
by different browsers.
// Browser detection var ie=document.all != null; //ie4 var op7=navigator.userAgent.indexOf("opera")>0 && operaVersion() <= 7; function operaVersion() { agent = navigator.userAgent; idx = agent.indexOf("opera"); if (idx>-1) { return parseInt(agent.subString(idx+6,idx+7)); } } /* Detection of the mouse button L M R IE,KON 1 4 2 event.button NS,OP8,FF 0 1 2 e.button OP7 1 3 2 e.button NS,OP8,FF 1 2 3 e.which */ var leftButton = ie? 1 : 0; // op7 supports document.all var middleButton = op7 ? 3 : ie ? 4 : 1; var rightButton = 2; document.onmouseup = onClick; // This code is executed each time a mouse button is released function onClick(e) { if (ie) { var elem = event.srcElement; var btn = event.button; //e = event; } else { var elem = e.target; var btn = e.button; } // elem is the element the user clicked on // btn is the mouse button which was used // e.g. if (btn == leftButton) { alert( elem + ": You clicked me!" ); } /* ...your code goes here... */ return false; }
原帖地址: http://snipplr.com/view/275/mouse-buttons-on-different-browsers/
相关文章推荐
- Linking different libraries for Debug and Release builds in Cmake on windows?
- highlight a DOM element on mouse over, like inspect does
- Result of Transforming XML by XSLT in Different Browsers
- onmouseenter,onmouseleave与onmouseover,onmouseout
- Using Images as Buttons on Windows Phone 7
- opencv鼠标操作setMouseCallback()与on_MouseHandle()
- Controls created on one thread cannot be parented to a control on a different thread
- Clarifications on Flash Player for Mobile Browsers, the Flash Platform, and the Future of Flash[翻译练习]
- How to create LOV on a reference attribute (a different approach)
- PullDownMenu.htm 和 onMouseOver,onMouseOut的使用
- CSS样式里使用JavaScript(onmouseover/onmouseout)
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
- ASP.NET2.0下为GridView添加鼠标滑过(onmouseover、onmouseout)的行颜色高亮效果!
- 点滴积累【JS】---JS小功能(onmouseover实现选择月份)
- JS小功能(onmouseover实现选择月份)实例代码
- ASP.NET2.0下为GridView添加鼠标滑过(onmouseover、onmouseout)的行颜色高亮效果!
- JavaScript onmousedown选择元素,onmousemove拖动元素,onmouseup松开鼠标,磁性吸附效果示例
- Change text color on listView with buttons
- Test your web design in different browsers[http://browsershots.org/]
- 兼容ie和firefox的鼠标经过(onmouseover和onmouseout)实现--简短版