最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Capture and Stop Middle Click - Stack Overflow

programmeradmin2浏览0评论

I know - this has been asked before, HOWEVER: People keep saying "you can't do that in Firefox", etc. etc. (specifically, this answer: Disabling middle click scrolling with javascript)

...then how does this do it? /

  1. It's in Prototype/Scriptaculous, but my Google-fu is failing me.
  2. I can't reproduce it in jQuery/MooTools (/)
  3. It looks tied to the Prototype implementation of events, but perhaps someone knows better than my quick investigation?

It captures the middle clicks, prevents a new window, and fires the correct event to open the overlay. I'm just not as familiar with Prototype as I am with the other libraries, and hope someone can point out the obvious.

TIA.

I know - this has been asked before, HOWEVER: People keep saying "you can't do that in Firefox", etc. etc. (specifically, this answer: Disabling middle click scrolling with javascript)

...then how does this do it? http://www.lokeshdhakar./projects/lightbox2/

  1. It's in Prototype/Scriptaculous, but my Google-fu is failing me.
  2. I can't reproduce it in jQuery/MooTools (http://jsfiddle/ezSR4/1/)
  3. It looks tied to the Prototype implementation of events, but perhaps someone knows better than my quick investigation?

It captures the middle clicks, prevents a new window, and fires the correct event to open the overlay. I'm just not as familiar with Prototype as I am with the other libraries, and hope someone can point out the obvious.

TIA.

Share Improve this question edited May 23, 2017 at 12:00 CommunityBot 11 silver badge asked Nov 30, 2010 at 20:29 keifkeif 5735 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

he is using the click event directly on the document object then it checks if it is on one of those picture links

so that would be the solution for right and middle click

  document.addEventListener("click", function(e){
    if(e.button == 1){
      e.preventDefault();
      alert(e.button);
    }
  }, true);
发布评论

评论列表(0)

  1. 暂无评论