I know I can do this:

}, "sp.js");

But I want to call SP.UI.ModalDialog.showModalDialog as soon as the page loads, without waiting for ExecuteOrDelayUntilScriptLoaded.

I saw SharePoint 2010 Modal Dialog on Page Load but that says to use ExecuteOrDelayUntilScriptLoaded.

I tried referencing the required JS files but then I get an error `Object doesn't support property or method 'get_staticObjects'.

<script type="text/javascript" src="/_layouts/init.js"></script>
<script type="text/javascript" src="/_layouts/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/sp.js"></script>
<script type="text/javascript" src="/_layouts/SP.UI.Dialog.js"></script>
  • check if Script On Demand is available in 2010, if so use SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { }); – Aveenav Feb 1 '16 at 22:04
  • SOD is there but it won't work on page loading. It only works after the page has finished loading. – IMTheNachoMan Feb 2 '16 at 0:45
  • Try require.js, then load all necessary dependent files (sp.js, sp.ui.dialog.js) then run the code. Put all these within <head> section. – Aveenav Feb 2 '16 at 1:08
  • unfortunately I am trying to do this in a CEWP and can't add code to the head. – IMTheNachoMan Feb 2 '16 at 13:02

Will need to add sp.runtime.js to this list as well..just below the init.js

|improve this answer|||||
  • Then I get the error 'IEnumerator' is undefined and Unable to get property 'noObjectPathAssociatedWithObject' of undefined or null reference – IMTheNachoMan Feb 3 '16 at 1:20
  • Please share your full code – Noah Wallace Feb 3 '16 at 1:32
  • I literally have a WebPart page with a CEWP pointing to an HTML file that only includes references to those 5 JS files. Just that. And when I go to the page I get those errors. – IMTheNachoMan Feb 3 '16 at 21:34

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.