如何禁用pdf文件的右键单击选项? [英] How to disable right click option for pdf file?

查看:2117
本文介绍了如何禁用pdf文件的右键单击选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在asp.net中禁用pdf文件的右键单击选项.
实际上,当我单击该按钮时,我有一个按钮pdf flie想要在单独的window.upto中正常工作.
但是我想禁用该pdf文件的右键单击选项.它没有得到....

请查看我的代码:

Sample1.aspx:

< script language =" javascript" type ="text/javascript">

函数btnWeek_onclick()

{
popupWindow = window.open(

"Sample2.aspx","mynewwin","height = 500,width = 600,status = yes,toolbar = no,menubar = no,location = no,scrollbars = yes,resizable = no,titlebar = no '');

}

</script>

< asp:按钮ID ="btnOpenPDF"; runat =服务器"文字=打开PDF"
OnClientClick =返回btnWeek_onclick()"/>

Sample2.aspx:

< script language =" javascript" type ="text/javascript">

//禁用Cntrl键的功能/右键单击
函数DisableControlKey(e)
{
//显示的消息
var message ="Cntrl键/已禁用右键单击选项";
//检查鼠标右键的条件/按下Ctrl键
if(e.which == 17 || e.button == 2)
{
警报(消息);
返回false;
}
}
</script>
< body onmousedown ="return DisableControlKey(event)">
< form id ="form1" runat =服务器">
< div>
</div>

</form>
</body

(Sample2.aspx)后面的代码
受保护的void Page_Load(对象发送者,EventArgs e)
{
Response.ContentType =应用程序/pdf;
Response.Clear();
Response.TransmitFile(E:\\ Desire-Determination-Dedication.pdf);
Response.End();
}

问候,
VenkiDesai.

Hi All,

How to disable right click option for pdf file in asp.net.
Actually i had a button when i click on that button pdf flie wants to be open in separate window.upto this working fine.
but i want to disable right click option for that pdf file.it was not getting....

Please see my code:

Sample1.aspx:

<script language="javascript" type="text/javascript">

function btnWeek_onclick()

{
popupWindow = window.open(

"Sample2.aspx", ''mynewwin'', ''height=500,width=600,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=no'');

}

</script>

<asp:Button ID="btnOpenPDF" runat="server" Text="Open PDF"
OnClientClick ="return btnWeek_onclick()"/>

Sample2.aspx:

<script language="javascript" type="text/javascript">

//Function to disable Cntrl key/right click
function DisableControlKey(e)
{
// Message to display
var message = "Cntrl key/ Right Click Option disabled";
// Condition to check mouse right click / Ctrl key press
if (e.which == 17 || e.button == 2)
{
alert(message);
return false;
}
}
</script>
<body onmousedown="return DisableControlKey(event)">
<form id="form1" runat="server">
<div>
</div>

</form>
</body

Code Behind for (Sample2.aspx)
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType =application/pdf;
Response.Clear();
Response.TransmitFile(E:\\Desire-Determination-Dedication.pdf);
Response.End();
}

Regards,
VenkiDesai.

推荐答案

尝试此线程,
如何使用以下方法禁用对asp.net网页的右键单击JavaScript |禁用鼠标右键单击网页 [ ^ ]

将此JavaScript包含在头部:
Try this thread,
How to disable right click on asp.net web page using JavaScript | Disable mouse right click on webpage[^]

Include this javascript in the head portion:
<SCRIPT LANGUAGE="JavaScript">
<!-- Disable
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
document.oncontextmenu=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
//-->
</script>


也请访问以下链接:单击此处 [这里 [


Visit the following links as well: click here[^]
Found it here[^]


这篇关于如何禁用pdf文件的右键单击选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆