1

I need some help. I'm very new to SharePoint development so please go easy on me.

Here is what I'm trying to do:

  • I need a Modal window to popup during page load of home.aspx to display a disclaimer with an "I Agree" button.
  • What I have so far is that while editing the CEWP it will popup everytime and close properly with the button but only while in edit mode.
  • Once I click OK and go back to the public shared view, it throws an error referencing SP.UI.ModalDialog.
  • SP.UI.ModalDialog is not a file on our SP2010 server.

Here is the code I'm using in the CEWP:

<script type="text/javascript">
 function codeAddress() {
    var options = {
         url: "http://devspf01/disclaimer.aspx" };
    SP.UI.ModalDialog.showModalDialog(options);
}
_spBodyOnLoadFunctionNames.push("codeAddress");</script>

This is the line it errors on: SP.UI.ModalDialog.showModalDialog(options);

Any help would be greatly appreciated!

Thanks,

Bg

1

SharePoint 2010: JavaScript error when creating Modal Dialog?

Use ExecuteOrDelayUntilScriptLoaded, to make sure it executes after sp.js is loaded!

<script type="text/javascript">
 function codeAddress() {

    ExecuteOrDelayUntilScriptLoaded(function () {
        var options = {
            url: "http://devspf01/disclaimer.aspx" };
        SP.UI.ModalDialog.showModalDialog(options);
     }, 'sp.js');
}
_spBodyOnLoadFunctionNames.push("codeAddress");</script>

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.