检测中键单​​击(滚动按钮)与jQuery [英] Detect middle button click (scroll button) with jQuery

查看:101
本文介绍了检测中键单​​击(滚动按钮)与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签列表来的onclick播放某些MP3文件。

:在使用jQuery的'click'事件绑定,当它工作正常

  $ oo.data({'__ mp3play':真,'wapiHandle:H + 0,'wapiIndex':o.ajaxPlayList [H]。长度})
           .bind('点击',()的函数
            {VAR WH =附加$ J(本)。数据(wapiHandle');
              如果(typeof运算o.regObjects [WH] =='对象'和;&安培; o.regObjects [WH] .play(this.href))
               {返回false; }
            });

当点击鼠标左键:
它禁用时,我的flash插件被加载,否则将正常打开默认处理。

但是:
当我使用鼠标的scrollbutton并点击它,点击事件不会触发,正常链接打开。

我曾尝试使用鼠标按下或鼠标松开事件,但没有帮助,链接始终与音乐开始与Flash Player还打副作用正常打开。

还有 preventDefault()行不通的。

有人可以告诉我如何检测鼠标中键点击(滚动按钮点击)?

感谢您的意见。

PS:我已经尝试过其他的解决方案,对中间按钮可在本网站

经测试,在所有类型的具有相同的结果浏览器。

编辑:
这也不起作用,使用鼠标中键时,链接将正常打开。当使用鼠标左键,没有发生。

  $ oo.bind(鼠标按下单击鼠标松开,功能(E)
{ÉpreventDefault(); e.stopPropagation();返回false; });


解决方案

好了家伙,

感谢您的输入。 @ no.good.at.coding有一个很好的解决方案,但在IE浏览器无法正常工作(见后面写这篇文章),但它是一个很好的起点。我改变了他的code这样:

  //避免关系将额外的选项卡单击中间滚动按钮,打开它的时候被打开
(文档)$ .bind($ browser.msie鼠标按下:?点击功能(E)
{
    如果(e.which == 2及和放大器; e.target.tagName =='A')
    {
        VAR BIE = $ .browser.msie,
            $ O = $(e.target)
            OE = $ o.data(事件),
            B =真,
            F =函数(){};        如果(typeof运算OE =='对象'和;&安培; OE ['点击']){
            F =函数(){$ o.trigger('点击'); }
        }其他{
            B =(typeof运算$的问题o [0] == .href'串'和;及($的问题o [0] == .TARGET未定义|| $问题o [0] .TARGET ==''|| $问题o [0 ] .TARGET =='_self'));
            如果(B)的{
                F =功能(){window.location.href = $的问题o [0] .href; };
            }
        }        如果(B!){返回; }        e.stopImmediatePropagation();
        e.stopPropagation();
        亦即preventDefault();        如果(BIE)
        {
            如果(!窗口.__ swcp__){
                窗口.__ swcp __ = $('< D​​IV style=\"position:fixed;top:0px;left:0px;width:100%;height:100%;background:#000;display:block;z-index:9999;opacity:0.01;filter:alpha(opacity:1);\" />').appendTo('body');
            }
            窗口.__ swcp __展()。
        }        的setTimeout(男,50);
        如果(BIE){
            的setTimeout(函数(){窗口.__ swcp __隐藏();},1000);
        }        返回false;
    }
});

中间的按钮现在的行为像一个鼠标左键。正如你所看到的IE浏览器需要更多的,我们必须在无焦点link标签1秒,以避免将在一个额外的标签中打开。我在这里使用一个简单的方法来做到这一点,创建一个'为眼透明格(不透明度= 0.01),将被放置在窗口内容,以便在页面上的任何链接将是重点不突出。
用户不会注意到任何区别,只是将鼠标指针从指针更改为默认一秒钟后,将其改回指针(仅适用于IE)。我可以忍受。

我接受这个作为一个答案,但如果你有更好的想法的让我知道。

I have a list with a tags to play some mp3 files onclick. It is working fine when binding on the 'click' event with jQuery:

$oo.data({'__mp3play':true,'wapiHandle':h+0,'wapiIndex':o.ajaxPlayList[h].length})
           .bind( 'click', function()
            { var wh = $j(this).data('wapiHandle');
              if( typeof o.regObjects[wh] == 'object' && o.regObjects[wh].play(this.href))
               { return false; }
            });

When clicking the left mouse button: It disables default handling when my flash plugin is loaded otherwise it will be opened normally.

BUT: When I use the scrollbutton of the mouse and click on it, the click event will not fired and the link opens normally.

I have tried to use mousedown or mouseup events but doesn't help, the link always opens normally with the side effect that the music starts playing also with the flash player.

Also preventDefault() does not work at all.

Can somebody tell me how to detect the middle mouse button click (scroll button click)?

Thank you for your comments.

PS: I have already tried other solutions about the 'middle button' available on this site.

Tested in all kind of browsers with the same result.

EDIT: This also does not work, the link will be opened normally when using the middle mouse button. When using the left mouse button, nothing happen.

$oo.bind( 'mousedown click mouseup', function(e)
{ e.preventDefault(); e.stopPropagation(); return false; });

解决方案

Okay guys,

Thank you for your input. '@no.good.at.coding' has a nice solution but does not work on IE (see later on this writing) but is a good starting point. I change his code to this:

// Avoid relations will be opened in extra tab when clicking middle-scroll-button to open it
$(document).bind($.browser.msie ? "mousedown" : "click", function(e)
{
    if (e.which == 2 && e.target.tagName == 'A') 
    {
        var bIE = $.browser.msie,
            $o = $(e.target),
            oe = $o.data('events'),
            b = true,
            f = function(){};

        if (typeof oe == 'object' && oe['click']) {
            f = function(){ $o.trigger('click'); }
        } else {
            b = (typeof $o[0].href == 'string' && ($o[0].target == undefined || $o[0].target == '' || $o[0].target == '_self'));
            if (b) { 
                f = function () { window.location.href=$o[0].href; };
            }
        }

        if (!b) { return; }

        e.stopImmediatePropagation();
        e.stopPropagation();
        e.preventDefault();

        if (bIE)
        {
            if (!window.__swcp__) { 
                window.__swcp__= $('<div style="position:fixed;top:0px;left:0px;width:100%;height:100%;background:#000;display:block;z-index:9999;opacity:0.01;filter:alpha(opacity:1);" />').appendTo('body'); 
            }
            window.__swcp__.show();
        }

        setTimeout(f, 50);
        if (bIE) { 
            setTimeout( function() { window.__swcp__.hide(); }, 1000 );
        }

        return false;
    }
});

The middle-button acts now like the left-button of a mouse. As you can see IE needs some more, we must unfocus the link tag for 1 second to avoid that it will be opened in an extra tab. I use here a simple way to do this, create a 'for the eye" transparent div (opacity = 0.01) that will be placed over the window content so any link on the page will be unfocused. The user will not notice any difference except that the mouse pointer can change from pointer to default and after one second it change back to pointer (IE only). I can live with that.

I accept this as an answer, but if you have better idea's let me know.

这篇关于检测中键单​​击(滚动按钮)与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆