首页 > 解决方案 > 右键单击 => 在 Angular 或 JS 中打印事件函数

问题描述

我想为所有类型的屏幕截图和打印编写函数。现在我想在 Angular 中编写右键单击和打印功能。如果有人知道破解,请告诉我。示例代码如下

  document.addEventListener('keydown', (e) => {
  if (e.ctrlKey && e.key == 'p') {
    // console.log("tried to print")
    // alert('This section is not allowed to print or export to PDF');
    this.prtScrEvent("Screenshot");
  }
});
//prtsc key press
window.addEventListener("keyup", (e) => {
  if (e.keyCode == 44) {
    // console.log("printing tried");
    // alert("The 'print screen' key is pressed");
    this.prtScrEvent("Screenshot");
  }
});

async prtScrEvent(status) {....}

标签: javascriptjqueryangularonclicklistenermouseclick-event

解决方案


看看这是否有助于右键单击。

document.addEventListener('contextmenu', (e) =>{
    // Your code
})

推荐阅读