需要阻止右键单击 PDF Angular 2
Need to block right click on PDF Angular 2
我在我的页面上的每个地方都禁用了右键单击,但仅在我动态生成的 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>
引用 link
最终可能的解决方案
Embed PDF on a webpage and prevent download
这些只是一个建议。
您可以使用 Host 属性 来禁用 app-card 组件
The host property is used to bind the events to all the attributes to
that particular class component
在您的应用卡片装饰器中,您需要定义主机 属性
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
host: {
'(contextmenu)': 'disableClick($event)'
}
然后你需要在你的app-card里面定义这个方法class
private disableClick(e){
e.preventDefault();
}
在此处查看此示例:https://stackblitz.com/edit/contextmenu-clickoutside
我在我的页面上的每个地方都禁用了右键单击,但仅在我动态生成的 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>
引用 link
最终可能的解决方案
Embed PDF on a webpage and prevent download
这些只是一个建议。
您可以使用 Host 属性 来禁用 app-card 组件
The host property is used to bind the events to all the attributes to that particular class component
在您的应用卡片装饰器中,您需要定义主机 属性
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
host: {
'(contextmenu)': 'disableClick($event)'
}
然后你需要在你的app-card里面定义这个方法class
private disableClick(e){
e.preventDefault();
}
在此处查看此示例:https://stackblitz.com/edit/contextmenu-clickoutside