Question

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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top