angular - 需要阻止右键单击 PDF Angular 2

标签 angular typescript angular6

我已经禁用了页面上每个位置的右键单击,但仅在我动态生成的 pdf 上我无法禁用它。

下面是 HTML 部分

<app-card *ngIf="show"> 
    <embed [src]="Url" type="application/pdf" width="100%" height="1000px" EnableContextMenu='0' >
</app-card>

这是 TS 部分,我还对 URL 进行了清理。

this.busy = this.http1.post('http://192.168.1.183:8200/api/auditUser', data).subscribe((res) => {
      if (res == 'Record Not found') {
        swal('No Record Found', 'Please Try Again', 'warning');
        this.show = false;
      } else {
        this.pdfPath = res;
        this.toolbar = '#toolbar=0';
        this.pdfSrc = 'http://192.168.1.183/' + this.pdfPath + this.toolbar;
        this.Url = this.sanitizer.bypassSecurityTrustResourceUrl(this.pdfSrc);
        this.show = true;
      }
    });

最佳答案

让我们尝试一次,

<script type="text/javascript">
document.onmousedown = disableRightclick;
var message = "Right click not allowed !!";
function disableRightclick(evt){
    if(evt.button == 2){
        alert(message);
        return false;    
    }
}
</script>

引用链接 https://googleweblight.com/i?u=https://www.codexworld.com/how-to/embed-pdf-disable-right-click-using-javascript/&hl=en-IN

第二种方式

<html>
<body oncontextmenu= "return false;">
Right Click not allowed on this page
</body>
</html>

引用链接

https://googleweblight.com/i?u=https://www.c-sharpcorner.com/forums/disable-right-click-on-ltembed-gt-pdf-file-in-sharepoint&hl=en-IN

最终为您提供可能的解决方案

Embed PDF on a webpage and prevent download

这些仅供引用。

关于angular - 需要阻止右键单击 PDF Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51317588/

相关文章:

javascript - 如何通过 Angular 2中的函数触发输入类型="file"的事件点击?

部署后 Angular 无法路由到延迟加载的模块

typescript - Angular2 - 发布候选路由器不路由到子路由

angular6 - 什么是 Angular 中组件的 Host 元素

javascript - Angular 6 表单在提交和重置后返回验证错误

javascript - Ionic 3 + Angular 4 + chart.js - 从数组加载数据

Angular2 RC6升级

javascript - 水平居中 MatDialog,宽度为 100%,最大宽度固定

angular - 如何将 trix-editor 集成到 Angular 2 应用程序中?

angular - 可以从异步管道调用类方法吗?