如何通过滚动按钮打开新的选项卡触发器

How to open a new tab trigger by the scroll button

本文关键字:选项 触发器 何通过 滚动 按钮      更新时间:2023-09-26

我正在制作一个php/html应用程序,在表中显示一些数据,当用户单击行(<tr>) jquery打开该记录。

这是代码:

$.fn.linkRow = function(element) {
    thisRow = this.find('tbody tr');
    thisRow.on('click', function() {
        hrefLocation = $(this).find('td.link:first a').attr('href');
        if (hrefLocation) {
            window.location.href = hrefLocation;
        };
    }).addClass((thisRow.has('td.link')) ? 'pointer' : '');
    return this;
};

事实是:用户不能在新选项卡中打开记录。唯一的方法是复制粘贴href…而我的用户不会那样做。

如果对滚动按钮触发的事件以及如何打开新选项卡进行一些研究,后者几乎是不可能的,所以…有人能想出办法吗?

编辑:通常这会在新选项卡中打开链接。

PS:我必须使用表格,在某些情况下,我会为此制作一个基于css的表格布局(不需要javascript),但我不能在这个版本的软件中做到这一点。


谢谢!

这是最终代码:

<>以前.fn美元。linkRow =函数(元素){thisRow = this。找到(tbody tr);thisRow.not (' a ')。On ('mouseup', function(e) {hrefLocation = $(this).find('td. location ')链接:第一:第一").attr("href");if (hrefLocation) {If (e.which == 2) {window.open (hrefLocation);}其他{window.location.href = hrefLocation;}};})。addClass((thisRow.has('td.link')) ?'指针':'');返回;}; 之前

但是…鼠标滚轮点击不工作,我的意图:

如果你点击链接(a标签)>打开一个新的选项卡

如果你点击一个无链接(任何其他标签)>,它将根据你的鼠标位置滚动。如果你向上移动鼠标,它就会向上滚动所以

所以…我的作品,但我肯定需要做一个没有javascript的解决方案。

如果你想让链接在一个新的选项卡中打开,而不是在同一个页面中,你需要替换

window.location.href = hrefLocation;

window.open(hrefLocation);

改变鼠标向上点击并捕捉值为2的e.with(中间按钮):

$.fn.linkRow = function(element) {
    thisRow = this.find('tbody tr');
    thisRow.on('mouseup', function(e) {
        hrefLocation = $(this).find('td.link:first a').attr('href');
        if ( hrefLocation ) {
           if (e.which == 2) { 
              window.open(hrefLocation);
           }
           else{
              window.location.href = hrefLocation;
           }
        };
    }).addClass( ( thisRow.has('td.link') ) ? 'pointer' : '' );
    return this;
};

尝试使用以下方法

$(document).scroll(function(){
if(!tabOpen){
    window.open('url', 'window name', 'window settings');
    tabOpen = true;
}
});

几个月前我也遇到过类似的问题。

要么将每个td-content包装成正常的a -Tag(并使用_target="blank"),在这种情况下不需要javascript !

...或者使用js:

thisRow.click(function(){
  window.open('url', 'window name', 'window settings');
  return false;
});

window.open()可以做到这一点,但这也取决于浏览器的配置

不确定滚动按钮是什么意思,但如果它是鼠标滚轮,那么您可以使用此脚本在滚轮上下时触发事件。

http://brandonaaron.net/code/mousewheel/demos

我不确定你是否想知道如何使用jquery制作中击事件或者如果你想知道如何打开一个新选项卡,但这里是:

中键事件:

$("tr").live('mousedown', function(e) { 
 if( (e.which == 2) ) {
   alert("middle button"); 
 }
   e.preventDefault();
});

新标签:

就像其他人所说的那样,使用以下语句:

window.open(href);

同时点击中键并打开链接:

$("tr").live('mousedown', function(e) { 
 if( (e.which == 2) ) {
    window.open(href);
 }
   e.preventDefault();
});
编辑:

一些来源:Jquery:检测鼠标中键或右键是否被点击,如果是,执行如下操作:

用jQuery检测中间按钮点击(滚动按钮)的答案也可以帮助解决一些与IE的兼容性问题

在新选项卡中打开:

window.open(hrefLocation);
window.open(hrefLocation,'_blank'); //Or this
window.open(hrefLocation,'_newtab'); //Or this