1

I already insert a snippet to create a new item inside a dialog box with this code:

<script type="text/javascript"> 
function displayLayover(url) {

 var options = SP.UI.$create_DialogOptions();

 options.url = url;

 options.dialogReturnValueCallback = Function.createDelegate(

 null, null);

 SP.UI.ModalDialog.showModalDialog(options);
 }
 </script>
 <a class="btn btn-orange" href='javascript:displayLayover("urlofsitecollection/subsite/subsite/Lists/List_Participants/NewForm.aspx?IsDlg=1")'>Create your profile</a>

Now my goal is to get the current site url, so I can use this snippet on different subsite and save the subsite as template. The name of the list will also be the same but the subsite will have different names. I would be more than grateful to get any help.

  • Current web url: _spPageContextInfo.webAbsoluteUrl. You can use _spPageContextInfo object to get the various details – nbi Sep 15 '17 at 13:58
1

You can use _spPageContectInfo object to get the current web url.

I have little modified your code to make url dynamic:

    <script type="text/javascript">
    function displayLayover(url) {
        var options = SP.UI.$create_DialogOptions();
        options.url = url;
        options.dialogReturnValueCallback = Function.createDelegate(null, null);
        document.getElementById("dialogButton").href=_spPageContextInfo.webAbsoluteUrl+"/Lists/List_Participants/NewForm.aspx?IsDlg=1";
        SP.UI.ModalDialog.showModalDialog(options);
    }
</script>  
<a id="dialogButton" class="btn btn-orange")'>Create your profile</a>
  • This is a huge help. I couldn't use the id but it worked totally fine with href. What would be the benefit to use getElementById? – Fabian Sep 19 '17 at 12:40
  • in this case jquery is not required. – nbi Sep 19 '17 at 13:18

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.