I've created a custom ribbon button where i load external content into a Modal Dialog. I want to insert some text on the editor and close the dialog. The function OnPopClosed is running when I click something on my dialog but I'm having an error: RTE is not defined, so I can't insert anything on the editor. Any ideas?

function init(){
    var options = SP.UI.$create_DialogOptions();
    options.title = "Sharepoint Plugin";
    options.width = 600;
    options.height = 400;
    options.url = '/_Layouts/Test/Test.aspx';
    options.dialogReturnValueCallback = OnPopClosed;
function OnPopClosed(test) {

    var range = RTE.Cursor.get_range();
    var selection = range.parentElement();
    if (!selection) {


    SP.UI.ModalDialog.commonModalDialogClose(1, "test");

Place RTE actions in SP.SOD.executeOrDelayUntilScriptLoaded in order to execute the specified function if the file containing it is loaded (in your case sp.ui.rte.js):

ExecuteOrDelayUntilScriptLoaded(RTEActions, "sp.ui.rte.js");


function RTEActions()
    var range = RTE.Cursor.get_range();
    //Place your remaining code here...
    SP.UI.ModalDialog.commonModalDialogClose(1, "test");

then declare the dialog handler like this:

function OnPopClosed() {
   ExecuteOrDelayUntilScriptLoaded(RTEActions, "sp.ui.rte.js");
  • It worked ! Actually I got over that RTE is undefined error, but I got another one that I'm going to post in a bit – nhenrique Sep 4 '13 at 9:04
  • Thanks for this answer! You might know the process to insert content into the editor after closing a Modal Dialog so if you could have a look at my new issue I'll appreciate. link – nhenrique Sep 4 '13 at 9:12
  • I'm glad I was able to help ;) – Vadim Gremyachev Sep 4 '13 at 9:16

The RTE only exists inside the editor, and your function OnPopClosed runs after the popup is closed. You need to run your script on Test.aspx rather than whatever page you're launching the dialog from.

  • I'm "inside the editor". What I do is to click on the editor, then click on my custom ribbon button. A window popups up, and then I just want to return a value to be pasted wherever the cursor is on the editor. I tried to put all the javascript code on Test.aspx but it doesn't make real sense since that file is the page for the modal dialog. – nhenrique Sep 3 '13 at 15:57
  • I meant to type "inside the dialog", sorry about that. And you're right, test.aspx is clearly the dialog url. What a worthless answer! Moving on: Is RTE undefined in the init function? – Chloraphil Sep 3 '13 at 19:13
  • Also, why the last line (SP.UI.ModalDialog.commonModalDialogClose... ) in function OnPopClosed? This function will be called when the dialog is closed. – Chloraphil Sep 3 '13 at 19:14
  • Yeah I was also a bit confused. I've been able to fix this with the solution that @Vadim posted. Thanks! – nhenrique Sep 4 '13 at 9:03

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.