中鼠点击链接只打开新标签ASP C#

时间:2017-03-02 21:51:45

标签: javascript c# jquery asp.net html5

1)如何检测到中间点击链接上的鼠标滚轮而不是右/左点击?

2)行为应该是鼠标中键点击链接的新选项卡,如果单击鼠标左键则在同一页面重新加载。 (与Chrome相同)。

3)ASP.Net,C#和链接是gridview中的第一个选择链接列。 Gridview第一列选择链接:

enter image description here

感谢。

2 个答案:

答案 0 :(得分:1)

您可以在JavaScript中使用此功能

function fixWhich(e) {
  if (!e.which && e.button) {
    if (e.button & 1) e.which = 1      // Left
    else if (e.button & 4) e.which = 2 // Middle
    else if (e.button & 2) e.which = 3 // Right
  }
}

答案 1 :(得分:1)

在Web表单中,您实际上可以使用服务器端来检测它。你可以这样做:

private void mouseClick(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Middle)
    {    
        //Open new window
    }
    else
    {
        //Open on the same window
    }
}

但是害怕在服务器端打开新窗口很难。所以最好使用客户端。

相关问题