"Object doesn't support property or method 'messageParent'" After login redirect in Office js
<p>I am trying to get a dialog to open in order to enter login credentials, but after being redirected back from the login authority I am no longer able to message the parent of the dialog window back with authorization codes or tokens.  If I do not redirect away from the page, I can message back to the parent, but otherwise I get the error in the title.  How can I message the parent (in this case the task pane) window with information from the dialog?</p>

<p>Below is the code I have to open and handle the dialog window:</p>

<pre><code>var dialog; 
function authenticate() {
    hideAll();
    Office.context.ui.displayDialogAsync('mydomain/Login',
        { height: 50, width: 25 }, dialogCallback);
}

function dialogCallback(asyncResult) {
    if (asyncResult.status === 'failed') {
        console.log(asyncResult.error.message);
    } else {

    dialog = asyncResult.value;
    dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
        DialogMessageReceived, messageHandler);
    dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
        DialogEventReceived, eventHandler);
    }
}

function messageHandler(arg) {
    showAll();
    console.log(arg);
    dialog.close();
}

function eventHandler(arg) {
    showAll();
    console.log(arg);
}
</code></pre>

<p>Here is the code that handles my login screen:</p>

<pre><code>Office.initialize = function (reason) {
$(document)
    .ready(function () {
        var code = $('#code').text();
        if (code !== '') {
            console.log(code);
            Office.context.ui.messageParent(code);
        } else {
            console.log('No code received from auth server');
        }
    });
};
</code></pre>