1

I have found a script that will run on click but I need it to run on page load.

<script type="text/javascript">
 //******** Basic Dialog Starts Here ***********/
 function openBasicDialog(tUrl, tTitle) {
     var options = {
         url: tUrl,
         title: tTitle
     };
     SP.UI.ModalDialog.showModalDialog(options);
 }
 //******** Basic Dialog Ends Here ***********/

With the Link code:

​</span><a onclick="openBasicDialog(&#39;/Emp1st/SitePages/Suggestion.aspx&#39;,&#39;Employee Suggestion Outline&#39;);" href="#"><span style="font-size: 14px;">Click Here.</span></a>

I have tried adding in

$(document).ready(function(){// code});

and

document.addEventListener('DOMContentLoaded', function() {
   // your code here
}, false);

but I have had no success. Any suggestions.


I tried this as you suggested.

<script>
ExecuteOrDelayUntilScriptLoaded(function(){
    var options = {
        url: /SitePages/testing.aspx,
        title: Test
    };
    SP.UI.ModalDialog.showModalDialog(options);
}, "sp.js");
</script>

Still no luck

1 Answer 1

1

Please try that:

<script>
    ExecuteOrDelayUntilScriptLoaded(function(){
        var options = {
            url: tUrl,
            title: tTitle
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }, "sp.js");
</script>
5
  • I tried your suggestion as seen above.
    – Andrew
    Aug 18, 2016 at 19:28
  • I assume you added quotation marks around the strings? What's the console saying, are there any error messages? How do you embed the code (Script Editor Webpart, Content Editor Webpart, Scriptblock, ..)? Is Minimal Download Strategy active? Aug 19, 2016 at 2:06
  • In trying this did you use the <script type='text/javascript'> ? Appears to be missing Aug 19, 2016 at 15:51
  • I basically never use the type attribute. I have never seen a scripting failing because of a missing type attribute. But it doesn't hurt to add it. Aug 19, 2016 at 16:09
  • Not sure why it didn't work the the other day when I tried but it worked today. I must have had a typo. Thanks for the help.
    – Andrew
    Aug 23, 2016 at 21:22

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.