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