0

Platform: SharePoint 2016

I am trying to use SharePoint's pop-up modal in SharePoint 2016 but it worked once and after a few minutes it stopped. I get the following error 'OpenPopUpPageWithTitle' is undefined

Any ideas what could be wrong?

Here's the code:

$(document).ready(function() {
    SP.SOD.executeFunc('sp.js', myPopUp());
});


function myPopUp() {
    var lsDate = localStorage.getItem("lastConnected");
    var tDate = new Date().toDateString().substring(4);
    if ((lsDate == null || lsDate == undefined) || (lsDate != tDate)) {
        showPopup();
        localStorage.setItem("lastConnected", tDate);
    }
}

function showPopup() {
    var url = "/SiteAssets/popup/my-Popup.html";
    var width = 680;
    var height = 470;
    OpenPopUpPageWithTitle(url, function(){return}, width, height, "Attention");
}

Thanks!

0

After googling, this worked for me

    $(document).ready(function() {  
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', showModalPopUp);  
    });  

    function showModalPopUp() {  
        //Set options for Modal PopUp  
        var options = {  
            url: '/sites/HOL/Pages/Custom-Publishing-Page.aspx?IsDlg=1', //Set the url of the page  
            title: 'SharePoint Modal Pop Up', //Set the title for the pop up  
            allowMaximize: false,  
            showClose: true,  
            width: 600,  
            height: 400  
        };  
        //Invoke the modal dialog by passing in the options array variable  
        SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);  
        return false;  
    }  ```
| improve this answer | |
0

You can also use the code below to achieve it.

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(myPopUp,'sp.ui.dialog.js');
function myPopUp() {
    var lsDate = localStorage.getItem("lastConnected");
    var tDate = new Date().toDateString().substring(4);
    if ((lsDate == null || lsDate == undefined) || (lsDate != tDate)) {
        showPopup();
        localStorage.setItem("lastConnected", tDate);
    }
}
function showPopup() {
    var url = "/SiteAssets/popup/my-Popup.html";
    var width = 680;
    var height = 470;
    OpenPopUpPageWithTitle(url, function(){return}, width, height, "Attention");
}
</script>
| improve this answer | |
  • Hi @LZ_MSFT, I get the following error when I try the above code: 'ExecuteOrDelayUntilScriptLoaded' is undefined – OLA Feb 14 at 13:38

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.