Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 0 down vote accepted

SharePoint 2010: JavaScript error when creating Modal Dialog?

Use ExecuteOrDelayUntilScriptLoaded, to make sure it executes are 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>
share|improve this answer
    
Thank you! That worked perfectly! –  BGill Dec 6 '12 at 18:52
    
Accept the answer as correct to close the question :) –  Arsalan Adam Khatri Dec 6 '12 at 18:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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