2
Answers

Create a Subsite using Javascript in SharePoint online,

Hello Friends,
i am using SharePoint online , i  have written a code to  create a sites using java script but i am getting null value in SPContext file .
please check the below code..
 
---------------------------------------------------------------------------------------------- 
<script type="text/JavaScript"
src="https://rajinfotech.sharepoint.com/Shared%20Documents/jquery-1.12.3.js"></script>
</script>
<script type="text/JavaScript"
src="https://rajinfotech.sharepoint.com/Shared%20Documents/MicrosoftAjax.js"></script>
<script type="text/javascript">
var clientContext ;
$(function(){
bindButtonClick();
});
function bindButtonClick() {
$("#btnSubmit").on("click", function (){
createSite();
});
}
function createSite() {
var collweb;
var siteTitle=$("#txtSiteTitle").val();
alert(siteTitle);
var siteDesc=$("#txtSiteDescription").val();
alert(siteDesc);
var siteUrl=siteTitle.replace(/\s/g, "");
alert(siteUrl);
clientContext =new SP.ClientContext();
alert(clientContext);
collweb=clientContext.get_web().get_webs();
alert(collweb);
var webCreationInfo=new SP.WebCreationInformation();
webCreationInfo.set_title(siteTitle);
webCreationInfo.set_title(siteDesc);
webCreationInfo.set_language(1033);
webCreationInfo.set_title(siteUrl);
webCreationInfo.set_useSamePermissionsAsParentSite(true);
webCreationInfo.set_webTemplate('STS#0');
var oNewWebsite=collweb.add(webCreationInfo);
clientContext.executeQueryAsync(Function.createDelegate(this,onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded() {
$("#divResults").html("Site successfully Created!");
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' +args.get_stackTrace());
}
</script>
<div id="DeleteFile">
<div>
<strong>Enter the Name Of the site:</strong>
<br/>
<input tpe="text" id="txtSiteTitle"/>
</div>
<br/>
<div>
<strong>Enter site Description:</strong>
<br/>
<textarea cols="20" id="txtSiteDescription"></textarea>
</div>
<br/>
<input type="button" id="btnSubmit" value="Submit">
</div>
<div id="divResults"></div>
 
Answers (2)