How to block all CTRL+V Operations in Editor?

9 posts, 0 answers
  1. Prince M. Premnath
    Prince M. Premnath avatar
    32 posts
    Member since:
    Oct 2009

    Posted 02 Mar 2010 Link to this post

    Hi ,

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

    Thanks
    Prince

  2. Rumen
    Admin
    Rumen avatar
    13278 posts

    Posted 02 Mar 2010 Link to this post

    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.
  3. Rumen
    Admin
    Rumen avatar
    13278 posts

    Posted 02 Mar 2010 Link to this post

    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.
  4. Important
    Important avatar
    6 posts
    Member since:
    Nov 2011

    Posted 20 Nov Link to this post

    Neither of these work because the CTRL+V event is not being captured (IE11).
  5. Rumen
    Admin
    Rumen avatar
    13278 posts

    Posted 20 Nov Link to this post

    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.
  6. Important
    Important avatar
    6 posts
    Member since:
    Nov 2011

    Posted 20 Nov in reply to Rumen Link to this post

    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.

  7. Important
    Important avatar
    6 posts
    Member since:
    Nov 2011

    Posted 20 Nov in reply to Rumen Link to this post

    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. 
  8. Rumen
    Admin
    Rumen avatar
    13278 posts

    Posted 20 Nov Link to this post

    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.
  9. Important
    Important avatar
    6 posts
    Member since:
    Nov 2011

    Posted 20 Nov in reply to Rumen Link to this post

    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();

    }

     

     

Back to Top