Javascript双击在IE9和IE11中不起作用

Javascript双击在IE9和IE11中不起作用,javascript,html,css,ajax,double-click,Javascript,Html,Css,Ajax,Double Click,在我的javascript代码中,单击鼠标会打开新选项卡中的链接,双击鼠标会打开灯箱。它在除IE9和IE11之外的所有浏览器中都可以正常工作。 在我的第一个代码中,单击和双击都可以工作,但对于单击,即给出消息,允许弹出窗口?我希望IE像其他浏览器一样,在新选项卡中打开链接而不显示消息。 在我的第二段代码中,单击可以按我所希望的方式工作,但IE中双击的第二次单击被忽略,并最终以单击方式工作。是否可以采取一些措施来消除我可能缺少的第一个代码或第二个代码中的问题 第一个代码:

在我的javascript代码中,单击鼠标会打开新选项卡中的链接,双击鼠标会打开灯箱。它在除IE9和IE11之外的所有浏览器中都可以正常工作。 在我的第一个代码中,单击和双击都可以工作,但对于单击,即给出消息,允许弹出窗口?我希望IE像其他浏览器一样,在新选项卡中打开链接而不显示消息。 在我的第二段代码中,单击可以按我所希望的方式工作,但IE中双击的第二次单击被忽略,并最终以单击方式工作。是否可以采取一些措施来消除我可能缺少的第一个代码或第二个代码中的问题

第一个代码:

                       $('div[id^="jzl_"].short').click(function(e) {
                              var $this = $(this);
                              var currentID = e.target.id;

                              if ($this.hasClass('clicked')) {
                                     $this.removeClass('clicked');
                                     $.colorbox({
                                            href : "getInfo1.php?id=" + currentID,
                                            overlayClose : false,
                                            top : "16%"
                                     });
                                     //$.colorbox({ overlayClose: false });
                                     //alert("Double click");
                                     //here is your code for double click
                              } else {
                                     $this.addClass('clicked');
                                     setTimeout(function() {
                                            if ($this.hasClass('clicked')) {
                                                   $this.removeClass('clicked');
                                                   //                                 alert("Just one click!");
                                                   var jobSite = window.open('', '_blank');
                                                   sleep(1000);
                                                   var redirct = getPage(currentID);
                                                   sleep(1000);
                                                   jobSite.location = redirct;
                                                   //var redirct = getPage(currentID);
                                                   //window.open(redirct, '_newtab' + Math.floor(Math.random() * 999999));
                                            }
                                     }, 500);
                              }
                       });
第二个代码:

                       $('div[id^="jzl_"].short').click(function(e) {
                              var $this = $(this);
                              var currentID = e.target.id;
                              var jobSite = window.open('', '_blank');
                              if ($this.hasClass('clicked')) {
                                     $this.removeClass('clicked');
                                     $.colorbox({
                                            href : "getInfo1.php?id=" + currentID,
                                            overlayClose : false,
                                            top : "16%"
                                     });
                                     //$.colorbox({ overlayClose: false });
                                     //alert("Double click");
                                     //here is your code for double click
                              } else {
                                     $this.addClass('clicked');
                                     setTimeout(function() {
                                            if ($this.hasClass('clicked')) {
                                                   $this.removeClass('clicked');
                                                   //                                 alert("Just one click!");
                                                   var redirct = getPage(currentID);
                                                   jobSite.location = redirct;
                                                   //var redirct = getPage(currentID);
                                                   //window.open(redirct, '_newtab' + Math.floor(Math.random() * 999999));
                                            }
                                     }, 500);
                              }
                       });

您应该同时使用.click和.dblclick,而不是测试元素是否具有clicked类。下面是新代码:

$('div[id^="jzl_"].short').dblclick(function(e) {

var $this = $(this);
var currentID = e.target.id;

$.colorbox({
href : "getInfo1.php?id=" + currentID,
overlayClose : false,
top : "16%"
});

//$.colorbox({ overlayClose: false });
//alert("Double click");
//here is your code for double click

});



$('div[id^="jzl_"].short').click(function(e) {

 var $this = $(this);
 var currentID = e.target.id;

 var jobSite = window.open('', '_blank');
 var redirct = getPage(currentID);
jobSite.location = redirct;

//var redirct = getPage(currentID);
//window.open(redirct, '_newtab' + Math.floor(Math.random() * 999999));

});

这一解决方案应在以下方面发挥作用:

var t = []; //timeout array
$('div[id^="jzl_"].short')
    .on('click', function(e) {
        var $this = $(this),
            currentID = e.target.id;

        // put each click in timeout array
        t[t.length] = setTimeout(function() {
            t = []; //reset timeout array
            alert('clicked: ' + currentID);

            //your code here

        }, 500);
    })
    .on('dblclick', function (e) {

        //cancel 2 timeouts and reset timeout array
        clearTimeout(t[0]);
        clearTimeout(t[1]);
        t = [];

        var $this = $(this),
            currentID = e.target.id;

        window.open('http://google.com', '_blank');
    });

Ola的演示中,您的代码中的dbl click不仅在IE中,而且在FF和Chrome中都以单键单击的方式工作。您切换了单击以打开警报和dblclick以在新选项卡中打开url。我将其切换回新选项卡中的单击打开url和dblclick打开警报,结果与我的第一个代码相同。如果你愿意,我可以把我的代码贴在你的代码下面。事实上,如果您在IE9或IE11中运行您的小提琴,单击一下就会调用IE消息允许弹出窗口?而不是在新选项卡中打开google.com。但是单击/dblclick逻辑是有效的,对吗?除了IE由于设置超时而显示允许弹出提示之外。当弹出窗口不是由用户事件触发时,将调用弹出窗口阻止程序。从技术上讲,在我们的例子中,弹出窗口是由用户事件单击触发的,但是对于IE来说,用户事件触发器由于设置超时而丢失。我会找到一个解决方案来解决这个问题。我试图找到一种方法来阻止IE弹出窗口阻止程序在setTimeout中阻止click事件,但没有成功。我研究了MSDN,发现如果在单击事件中使用setTimeout方法,弹出窗口将不会启动。好了,没办法了。为什么不像我最初建议的那样反转逻辑——在dblclick事件上打开弹出窗口,在click事件上执行另一个操作?在dblclick事件中打开弹出窗口不会被阻止,因为它不在setTimeout内。是的,我需要的是当单击用于在新选项卡中打开url时,即不应显示允许弹出提示。