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.