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

How to block all CTRL+V Operations in Editor?

8 Answers 347 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Prince M. Premnath
Top achievements
Rank 2
Prince M. Premnath asked on 02 Mar 2010, 10:35 AM
Hi ,

 I wish to block all Ctrl+ V Operation in Rad Editor , how just i can do this ?

Thanks
Prince

8 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 02 Mar 2010, 10:57 AM
Hi Prince,

You can disable the Pasting in IE and Firefox using the code below:
<script type="text/javascript">
    function OnClientPasteHtml(editor, args)    
    {    
        if (args.get_commandName() == "Paste")    
        {
            args.set_cancel(true);    
        }    
    }    
</script>    
<telerik:RadEditor     
    ID="RadEditor1"     
    OnClientPasteHtml="OnClientPasteHtml"      
    runat="server">    
</telerik:RadEditor>

It is not possible to cancel the Ctrl+V shortcut in Chrome / Safari because they do not offer onpaste client-side event and we cannot cancel the paste process.

Best regards,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rumen
Telerik team
answered on 02 Mar 2010, 11:05 AM
This is a quick follow-up,

What you can also do is to attach the Ctrl+V shortcut to another command of RadEditor and assign some strange shortcut to the Paste button, e.g.

ToolsFile.xml file:

<tool name="Paste" shortcut="CTRL+!"/>
<tool name="Help" shortcut="CTRL+V" />

This should work in all browsers.

Sincerely,
Rumen
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Important
Top achievements
Rank 1
answered on 20 Nov 2017, 03:13 PM
Neither of these work because the CTRL+V event is not being captured (IE11).
0
Rumen
Telerik team
answered on 20 Nov 2017, 03:59 PM
Hi,

I tested the code sample and it works properly on my end as you can see in the video: https://www.screencast.com/t/x5aLld32.

<script type="text/javascript">
    function OnClientPasteHtml(editor, args)    
    {    
        if (args.get_commandName() == "Paste")    
        {
            args.set_cancel(true);    
        }    
    }    
</script>    
<telerik:RadEditor     
    ID="RadEditor1"     
    OnClientPasteHtml="OnClientPasteHtml"      
    runat="server">    
</telerik:RadEditor>


For your convenience I have attached my test project.

If it does not work properly, please have in mind that the Paste command may not work as expected, because browsers tend to change the HTML the user pastes. Another reason could be that the Paste operation via Script option can be disabled in your IE browser - https://www.screencast.com/t/GHeuzY24cw.

Regards,
Rumen
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Important
Top achievements
Rank 1
answered on 20 Nov 2017, 04:34 PM

I downloaded DisablePaste.zip and got the same result.  As soon as the editor comes up, place the cursor in the textarea and hit CTRL-V.  The pasted text immediately appears with all the fonts and other attributes as the source.  If I use the various Paste options from the toolbar, the OnClientHTMLPaste event is always triggered nut no on the CTRL-V.  Unfortunately, I have the PasteAsText button bound to CTRL-V and the result is that I get two pastes--on as text and one as whatever is in the clipboard.

I've tried binding to the textarea (in the editor) to disable the paste op but that doesn't seem to work even though it works outside of the RadEditor control.  It's possible IE11 is just too cranky.  It works nicely in browser compatability mode.

0
Important
Top achievements
Rank 1
answered on 20 Nov 2017, 04:57 PM
I believe you are right about the "Allow Programmatic clipboard access" setting on the browser.  I can't actually look at the settings since it's a locked down enterprise but it seems very likely.  I couldn't see your screen snap earlier of the settings panel, it required Adobe Flash and that's locked down too!  The security team really wrecks havoc with us.  But okay, I see what's happening now so I'm happy. 
0
Rumen
Telerik team
answered on 20 Nov 2017, 05:13 PM
You said that you've applied the Ctrl+V shortcut to the Paste Plain Text too. In this case you can try to attach to the onkeydown event and prevent the execution of the Ctrl+V command. See this resources:
https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/client-side-programming/methods/attacheventhandler
https://stackoverflow.com/questions/2903991/how-to-detect-ctrlv-ctrlc-using-javascript

Regards,
Rumen
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Important
Top achievements
Rank 1
answered on 20 Nov 2017, 05:58 PM

That's perfect!  All I did was add was add a couple of lines to the OnClientLoad and now the CTRL-V uses PasteAsText to copy to the clipboard.  The default paste has been replaced by specifying it as the shortcut on the tool atributes.  Many thanks!

 

editor.attachEventHandler("paste", function (e) {

 

 

e.preventDefault();

}

 

 

Tags
Editor
Asked by
Prince M. Premnath
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Important
Top achievements
Rank 1
Share this question
or