I create a simple webpart :

<div class="btn" onclick="SP.UI.ModalDialog.showModalDialog({url: &#39;<%= URL_A %>?IsDlg=1&#39;, title: &#39;Nouvelle Demande&#39;,allowMaximize: true,showClose: true});return false;">Ajouter</div>

And the button doesntwork properly :

Uncaught TypeError: Cannot read property 'defaultDialogWidth' of undefined

In master page I add ALL references :

<script src="/_layouts/15/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/_layouts/15/ie55up.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.core.js" type="text/javascript"></script>
    <script type="text/javascript" src="/_layouts/15/ScriptResx.ashx?name=sp.res&culture=en-us"></script>
    <script type="text/javascript" src="/_layouts/15/sp.init.js"></script>
    <script src="/_layouts/15/sp.ui.dialog.js" type="text/javascript"></script>
    <script src="/_layouts/15/core.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.js" type="text/javascript"></script>
    <script src="/_layouts/15/inplview.js" type="text/javascript"></script>
    <script src="/_layouts/15/cui.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.ribbon.js" type="text/javascript"></script>
    <script src="/_layouts/15/mdn.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.ui.pub.ribbon.js" type="text/javascript"></script>

    <script src="/_layouts/15/socialdata.js" type="text/javascript"></script>
    <script src="/_layouts/15/sp.ui.socialribbon.js" type="text/javascript"></script>
    <script src="/_layouts/15/cui.js" type="text/javascript"></script>
    <script src="/_layouts/15/wpadder.js" type="text/javascript"></script>
    <script src="/_layouts/15/search.js" type="text/javascript"></script>

yes, the code is loaded , in fact on one enviroment the button works fine , on other sharepoint enviroment i got this error !!!!

Any idea?

  • 1
    Use F12 to check what code is created for your Button by {url: &#39;<%= URL_A %>?IsDlg=1&#39; Then copy paste that code and edit/use it in the F12 console until you get the syntax right May 15, 2017 at 10:26
  • yes, the code is loaded , in fact in one enviroment teh button work fine , on other sharepoint enviroment i got this error !!!!
    – Imen Turki
    May 15, 2017 at 10:28
  • Then it is not the same code/environment.. I suspect an issue with quotes May 15, 2017 at 10:37

1 Answer 1


Based on the error reported by Firefox, I suppose that your method is failing because the SP.js script file is "lazy loaded" and thus not fully loaded when your logic executes.

If this is the case, you need to delay the execution of your function until the script has been loaded. You can do this by using the ExecuteOrDelayUntilScriptLoaded function.

ExecuteOrDelayUntilScriptLoaded(SomeFuction, "SP.js")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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