我已经禁用了页面上每个位置的右键单击,但仅在我动态生成的 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>
第二种方式
<html>
<body oncontextmenu= "return false;">
Right Click not allowed on this page
</body>
</html>
引用链接
最终为您提供可能的解决方案
Embed PDF on a webpage and prevent download
这些仅供引用。
关于angular - 需要阻止右键单击 PDF Angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51317588/