2

I am trying to get a modal to appear when the site loads.

  • I created a site page called Disclaimer.aspx and stored it in the Site Pages document library.
  • I created a text document called popup.txt and stored it in my Shared Documents.
  • I added a content editor webpart to my home screen and linked it to the popup.txt file

Onload the page displays the modal however, the Disclaimer.aspx page isn't showing. I am getting a Error: An unexpected error has occurred

Contents of popup.txt:

 <SharePoint:ScriptLink ID="ScriptLink21" Name="sp.js" runat="server" OnDemand="true" 

Localizable="false" />

<script type="text/ecmascript">
    ExecuteOrDelayUntilScriptLoaded(ShowDialog, "sp.js");

    function ShowDialog() {

        var options = {
                url: '../SitePages/Disclaimer.aspx',
                height: 500,
        };

        SP.UI.ModalDialog.showModalDialog(options);
    }
</script>

I tried the code with the full path and I get the same error.

Error

  • Try with adding script editor webpart on page and add your modal pop up script in it. remove content editor webpart. – SP Developer Sep 20 '16 at 18:01
  • The CEWP method should work. But, I would not be calling the same page modal from within the page, It sounds recursive to me. – Ransher Singh Sep 20 '16 at 18:14
  • There's a correlation ID. Can you check what's the error in the uls logs? My guess is that's related to the target page itself, not the way you open the page. – Steve B Sep 22 '16 at 15:21
1

You should first ensure that the Disclaimer.aspx is not a wiki page it should be web part page to avoid An unexpected error has occurred ,

If everything is OK , try to add the following code at your CEWP

<a href="#" onclick="javascript:SP.UI.ModalDialog.showModalDialog({ url: '../SitePages/Disclaimer.aspx', title: 'Disclaimer' }); return false;"  >Click Here</a>

Also, you can try to use the following code

 <script>
function openDialog(pageUrl) { 
var options = {
    url: pageUrl,
    title: 'Title of the Dialog',
    allowMaximize: false,
    showClose: true,
    width: 500,
    height: 500
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);       
}

</script> 
<a href="#" onclick="openDialog('http://path/SitePages/Disclaimer.aspx');">Disclaimer</a>

Both samples have been worked for me without issue ,

Check also the detail steps at Open a link via Modal Dialog in SharePoint

  • Does disclaimer.aspx need to be a webpart page or can it be a wiki page? – Jammin4CO Sep 22 '16 at 15:23
  • 1
    Dear @Jammin4CO it's very good question , I am pretty sure it only works for web part page not wiki, the behavior that he mentioned in his question is because he uses wiki page not web part page, I also update my answer with this info, and this mentioned in the attached article – Mohamed El-Qassas MVP Sep 22 '16 at 16:16
0

Remove the below from popup.txt since these tags don't work\belong here

SharePoint:ScriptLink ID="ScriptLink21" Name="sp.js" runat="server" OnDemand="true" Localizable="false" />

Add the sp.js explicitly using script> tag

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.