Thursday, 1 January 2015

Display Title of a Sharepoint Site using Javascript Client Object Model


Thanks to Praveen..a simple program to display title of a sharepoint site using javascript client object model

http://praveenbattula.blogspot.in/2010/02/sharepoint-2010-client-object-model.html


Add a webpart page to sharepoint site
Add content editor webpart
Edit content editor webpart
Copy and paste the content mentioned below in HTML mode and save the webpat page


<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getWebSiteData, "sp.js");
var context = null;
var web = null;
    function getWebSiteData() {
        context = new SP.ClientContext.get_current();
        web = context.get_web();
        context.load(web);
        context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
    }
    function onSuccessMethod(sender, args) {
        alert('web title:' + web.get_title() + '\n ID:' + web.get_id());
    }
    function onFaiureMethodl(sender, args) {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    }
</script>



No comments:

Post a Comment