Hide the “created by” and “last modified by” on a SharePoint 2013 dispform with JavaScript

September 23rd, 2013 | Posted by Marijn in design | document management | jquery / javascript | SharePoint 2013

A client was creating a public site and wanted to show a list of documents with the “more info” link.
The visitors shouldn’t see the person who has created and modified the document, so we need to hide that information from the dispform.

This is very easy with JavaScript and jQuery. A quick look with the “Internet Explorer Developer tool” shows us that the bottom lines are just span elements. They have unique ID’s but they are very long and unique per library. The “td” element which capsulates the span has an easy to read id though!

ID’s for the elements

These are the ID’s for the elements:

onetidinfoblock1: created on this date x by person y
onetidinfoblock2: last modified on this date x by person y
onetidinfoblockV: version x

Getting the element ID

Getting the element ID

Hide the fields with JavaScript

Edit the dispform (via the browser by clicking on the cog – edit page) and add a script editor webpart. Make sure the script editor web part is the bottom one! Add this code in the script editor, save and test!


<script type=text/javascript>
//hide created
document.getElementById("onetidinfoblock1").innerHTML=" ";
//hide last modified
document.getElementById("onetidinfoblock2").innerHTML=" ";
//hide version
document.getElementById("onetidinfoblockV").innerHTML=" ";
</script>

Hide the fields with jQuery

Edit the dispform (via the browser by clicking on the cog – edit page) and add a script editor webpart. Make sure the script editor web part is the bottom one! Add this code in the script editor, save and test!
Don’t forget to refer to the jQuery file!


<script type=text/javascript>
//hide created
$("[id='onetidinfoblock1']").hide();
//hide last modified
$("[id='onetidinfoblock2']").hide();
//hide version
$("[id='onetidinfoblockV']").hide();
</script>

The fields are hidden

The fields are hidden

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

3 Responses

  • julia says:

    how can I add a if statement to this? hide certain fields only when the value of a certain field is equal to x let’s say..Thanks in advance

  • Jay says:

    thank you! works on the 2010 dispform also. Using view souce, I saw the same IDs

  • Dhandapani says:

    I have full control and i did the same and its working for me. But people have contribute level access. They are able to see “Created by” and “Modified by”. So need to hide permanently.



Leave a Reply

%d bloggers like this: