Wednesday 6 October 2010

Image Copyright. C#

I needed to write some code to prevent images being copied.
Although not ideal (user can still view source, or use PrintScreen), this at least makes it harder for users to copy images directly.

public static void PreventRightClickOnHtmlControl(HtmlControl htmlControl)
{
htmlControl.Attributes["onmousedown"] += "return false";
htmlControl.Attributes["onclick"] += "return false";
htmlControl.Attributes["oncontextmenu"] += "return false";
}

Page.ClientScript.RegisterClientScriptBlock(GetType(), "DisableImageDrag", "document.ondragstart = function () { return false; };", true);

No comments:

Post a Comment