2

I know I can do this:

ExecuteOrDelayUntilScriptLoaded(function()
{
    SP.UI.ModalDialog.showModalDialog(..)
}, "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>
4
  • check if Script On Demand is available in 2010, if so use SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { });
    – Aveenav
    Commented Feb 1, 2016 at 22:04
  • SOD is there but it won't work on page loading. It only works after the page has finished loading. Commented Feb 2, 2016 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
    Commented Feb 2, 2016 at 1:08
  • unfortunately I am trying to do this in a CEWP and can't add code to the head. Commented Feb 2, 2016 at 13:02

1 Answer 1

1

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

3
  • Then I get the error 'IEnumerator' is undefined and Unable to get property 'noObjectPathAssociatedWithObject' of undefined or null reference Commented Feb 3, 2016 at 1:20
  • Please share your full code Commented Feb 3, 2016 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. Commented Feb 3, 2016 at 21:34

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.