2

When I click on Edit Page button the code below doesn't execute, but I have all permissions:

<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ViewPages">
   <script type="text/javascript">
      document.getElementById("suiteBar").style.display = "block";
      if (document.getElementById("Ribbon") != null) {
        document.getElementById("s4-ribbonrow").style.display = "block"; 
      }
   </script>
</SharePoint:SPSecurityTrimmedControl>
  • How are you hiding the ribbon? In css then you need to display it in JS? – Mohamed Derhalli Dec 15 '16 at 17:19
  • Yes it's hidden in css – Dmitry Dec 15 '16 at 17:34
2

I've found the reason. The problem was in this condition - if (document.getElementById("Ribbon") != null) but no in SharePoint:SPSecurityTrimmedControl. Thank's everyone for your answers.

| improve this answer | |
  • Great. Mark it as an answer so others will recognize it – Mohamed Derhalli Dec 15 '16 at 18:17
0

Try to run this code after sharepoint UI is loaded:

_spBodyOnLoadFunctions.push(function(){
    document.getElementById("suiteBar").style.display = "block";
      if (document.getElementById("Ribbon") != null) {
        document.getElementById("s4-ribbonrow").style.display = "block"; 
      }
});
| improve this answer | |
  • It's ok, but this code will run for all users. Expected behavior is that for users with Read Only permissions this code shouldn't be executed – Dmitry Dec 15 '16 at 17:01
  • What do you mean? – Sergei Sergeev Dec 15 '16 at 17:03
  • Users with Read Only permissions shouldn't see the ribbon – Dmitry Dec 15 '16 at 17:12
  • From your question I understand that you are not able to run your code in edit mode, right? – Sergei Sergeev Dec 15 '16 at 17:21
  • Yes, the code isn't executed in the edit mode. The ribbon should be displayed always for certain category of users – Dmitry Dec 15 '16 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.