I'm doing some custom ribbon buttons (sandbox solution) to extend RTE in an Sharepoint Foundation 2010 environment.

For this i need to perform some actions on the RTE field using jquery before saving it to clean the code..

On List richtext fields i got it using the presaveaction() function to hold my js code, but for what i realized, this do not work on saving wikipages.

Any ideas? any RTE or CUI function that i can hijack to put my code?


Maybe the onbeforeunload event can do that for you.

Keep in mind that this will only work if your code is synchronous.

window.onbeforeunload = function() {
    console.log('insert your code here');

If that is no option for you, heres a small untested hack:

    _baseCoreInvoke = CoreInvoke;
    CoreInvoke = function(task, target){
        if(target.getAttribute('_action') === 'save'){
            console.log('your code here');
        // call original function
        _baseCoreInvoke.apply(window, arguments);
| improve this answer | |
  • Tks MX, onBeforeUnload almost worked, tryed it checking typeof(RTE) != 'undefined' to see if leaving the editmode, but got some problems when adding webparts , it fired too.. but found other way.. – Alvaro Murtinho Jul 30 '16 at 21:56

Thanks all, find another way. Hijacked the


Worked till now, doing more tests.

SP.SOD.executeOrDelayUntilScriptLoaded(hooksave, 'SP.js');
function hooksave() {
if (
  SP.Application.UI.WikiPageNameInPlaceEditor.prototype.savingPageCallbackOrig = SP.Application.UI.WikiPageNameInPlaceEditor.prototype.savingPageCallback;
  SP.Application.UI.WikiPageNameInPlaceEditor.prototype.savingPageCallback =
  function() { 

| improve this answer | |

For me, neither overriding SP.Application.UI.WikiPageNameInPlaceEditor.prototype.savingPageCallback, CoreInvoke or using onbeforeunload allowed me to edit wiki content before saving.

But using this method I could (SharePoint 2013 and Enterprise Wiki Page):

ExecuteOrDelayUntilScriptLoaded(function () {
    var originalCallCommandHandler = CUI.Page.CommandDispatcher.prototype.callCommandHandler;
    CUI.Page.CommandDispatcher.prototype.callCommandHandler = function (handler, commandId, properties, sequenceNumber) {
        //"PageStateGroupSaveSplit" is passed either when pressing Page -> Edit in ribbon or Save when in edit mode. Presence of RTE object means we are in Edit mode.
        var saveCommands = ["PageStateGroupSaveSplit", "PageStateGroupSave", "PageStateGroupSaveAndPublish"];
        if (saveCommands.indexOf(commandId) > -1 && typeof RTE !== "undefined") {
            var currentEditableRegion = RTE.Canvas.currentEditableRegion();
            //Do something with currentEditableRegion 

        return originalCallCommandHandler(handler, commandId, properties, sequenceNumber);
}, "cui.js");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.