Description:
The purpose of this component is to restrict the copy option from the user level of apex page.
SCENARIO :
- Consider in our apex application we are providing any confidential message or data
that should not be copied by the user level; we can restrict by this component.
- If we want to provide any notification message for restrict the copy option for that
particular confidential page, we can use this component.
STEPS TO DO:
1.Create a page in apex and use the region to display some text that to restrict copy option
- In that region, source type the script that given below and save the page and run it.
SCRIPT EXPLANATION:
We can restrict the copy option in these ways,
- Restrict Ctrl+C Button.
- Restrict Mouse Right-click.
This script will restrict these two ways,
//Restrict Ctrl+C Button in javascript
<head>
<script language=”javascript”>
<!–
function Disable_Control_C() {
var keystroke = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && keystroke == ‘c’) {
event.returnValue = false;
alert(‘You can not copy here’); }
}
</script>
</head>
//This script will restrict the CTRL+C and stop the action in user level
<body onkeydown=”javascript:Disable_Control_C()”> </body>
</html>
//Disable right mouse click Script for IE(Internet Explorer)
<script language=JavaScript>
var message = “Mouse Right Click Disabled!”;
function clickIE4() {
if (event.button == 2) {
alert(message);
return false;
}
}
//Disable right mouse click Script for another browser
function clickNS4(e) {
if (document.layers || document.getElementById && !document.all) {
if (e.which == 2 || e.which == 3) {
alert(message);
return false;
}
}
}
//Here we are restrict the mouse event and mouse down event
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS4;
} else if (
document.all && !document.getElementById) {
document.onmousedown = clickIE4;
}
document.oncontextmenu = new Function(“alert(message);return false”)
</script>
3.We can execute this query anywhere in the region source or in the HTML attribute
4.Here I have provide some screen-shots that will helpful for your reference.
SCREENSHOT
- If the user tries to copy the page using CTRL+C, then automatically user will get this notification.
- If the user tries to copy by mouse then, user will get this notification that “Mouse Right
Click Disabled”.
Summary:
This Post explained what the steps should follow to create restrict Copy Paste & Right Click In Apex Page.
Queries?
Do drop a note by writing us at doyen.ebiz@gmail.com or use the comment section below to ask your questions.