This is a migrated thread and some comments may be shown as answers.

Any way to prevent Ctrl+V in Chrome?

1 Answer 67 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Graham
Top achievements
Rank 1
Graham asked on 08 Feb 2012, 12:13 AM
I'm working on a project where they want us to prevent any of the users from pasting into the RadEditor, and I was able to get it working in IE and Firefox (finally), but Chrome just lets me paste right into the box and I cant seem to make it stop. The JavaScript I am using to prevent Pasting is as follows.

<script type="text/javascript" language="javascript">
 
    // Prevents pasting into RadEditor
    // from RadEditor menu and Context menu
    function OnClientCommandExecuting(editor, args) {
 
        var commandName = args.get_commandName();
 
        if (commandName == "PasteFromWord"
        || commandName == "PasteFromWordNoFontsNoSizes"
        || commandName == "PastePlainText"
        || commandName == "PasteAsHtml"
        || commandName == "Paste") {
 
            args.set_cancel(true);
        }
        //alert(commandName);
    }
 
    // Prevents pasting into RadEditor
    // by pressing Ctrl + V
    function OnClientLoad(editor) {
 
        editor.attachEventHandler("onkeydown", function (e) {
 
            if (e.ctrlKey && e.keyCode == 86) {
 
                if (document.all) {
                    e.cancelbubble = true;
                    e.returnvalue = false;
                    return false;
                }
                else {
                    e.preventdefault();
                    return false;
                }
            }
 
        });
 
        // Prevents Firefox from loading the context menu.
        editor.attachEventHandler("oncontextmenu", function (e) {
            if (e.preventDefault) e.preventDefault();
            if (e.stopPropagation) e.stopPropagation();
            return false;
        });
    
</script>

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Feb 2012, 07:21 AM
Hello Graham,

Check the following forum thread which discussed similar scenario.
How to block all CTRL+V Operations in Editor.

-Shinu.
Tags
Editor
Asked by
Graham
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or