Saturday, September 3, 2011

Remove format when copy paste in rich text editor

Share/Save/Bookmark

How do i avoid the formatting that comes along when i copy paste content from a site or word document to the Rich Text Editor (RTE) field in sharepoint? Ofcourse RTE already have an option Clear Formatting that can be used to clear after pasting the content,, but i do not want the format to be copied at first. So after digging into SP.UI.RTE.js and googling i have come up with a small script that will not paste the markup but only text.


    //Disable the RTE paste option. Restricts to "Paste Plain Text"
    function disableMarkupPasteForRTE()
    {
     Type.registerNamespace("RTE");
     if (RTE)
     {
      if(RTE.RichTextEditor != null)
      {
       RTE.RichTextEditor.paste = function() { RTE.Cursor.paste(true); }
       // Handle Ctrl+V short cut options in rich text editor
       RTE.Cursor.$3C_0 = true;
      }
     }
    }

I used the below standard sharepoint javascript function that will run the above or any javascript function on load of page.

    _spBodyOnLoadFunctionNames.push("disableMarkupPasteForRTE");


 Subscribe

5 comments:

  1. I'm guessing this does not work with SharePoint 2007?

    ReplyDelete
    Replies
    1. i doubt that as SP.UI.RTE.js was not there in SP2007

      Delete
  2. A solution for Firefox? Its works fine in Explorer.

    ReplyDelete
  3. Hi MJ - great post; exactly what I'm looking for.

    I'm fairly new to SP developing - how do I apply this to a masterpage?

    ReplyDelete
  4. hi,
    how to implement this for the people picker inputuser field in sharepoint 2010? when i copy an email address from my outlook, it copies the html tag href=mailto; with it and i'd like to get rid of that.
    thanks

    ReplyDelete