0

Using JavaScript, I need to retrieve from a sharepoint pages. These information

  • Title of the pages

  • Contents

  • images.

Thank you very much

1 Answer 1

2

To Get Page Title

You can use (SP.js) to Get Web Site Properties like Title, Description, Language ....etc.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function () {
    // Wait until SP.JS has loaded before calling getWebUserData 
    ExecuteOrDelayUntilScriptLoaded(retrieveWebSite, "sp.js");
});

function retrieveWebSite() {
   var clientContext = new SP.ClientContext("http://epm/workflow");
   this.oWebsite = clientContext.get_web();
   clientContext.load(this.oWebsite);
   clientContext.executeQueryAsync(
      Function.createDelegate(this, this.onQuerySucceeded), 
      Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded(sender, args) {
   alert('Title: ' + this.oWebsite.get_title());
}

function onQueryFailed(sender, args) {
  alert('Request failed. ' + args.get_message() + 
      '\n' + args.get_stackTrace());
} 
</script>

For more details check Get web title from ClientContext using URL?


To get Page Content

Use the below endpoint to get the Publishing Page Content.

/_api/Web/Lists/getByTitle('Pages')/items(<item id>)?$select=PublishingPageContent

For more details check How to get content of html by using REST service in SharePoint 2013


To get all images URL in the page

var array = [];
var images = document.getElementsByTagName("img");
for(var i=0, max=images.length; i<max; i++) {
    array.push(images[i].href);
}

If you need to get Publishing image field, Check Retrieve Publishing image field with SharePoint

1

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.