What do you think? Discuss, post comments, or ask questions at the end of this article [More about me]

Problem

Confluence allows public (anonymous) viewing/access to spaces and pages.  For various reasons one might want to disable various elements on a space or page.

Solution

We can use custom html features to add javascript to disable features for specific users (e.g. anonymous users).  For example, to disable the tool menu (see top right) and the  menu for anonymous users simply add the following javascript to the "At end of the HEAD" section (General configuration → custom HTML):

<script type="text/javascript">
    AJS.toInit(function(){
        if (AJS.params.remoteUser == ''){
            AJS.$('#action-menu-link').hide();
            AJS.$('#quick-search').hide();
            AJS.$('#help-menu-link').hide();
            AJS.$('#space-tools-menu-trigger').hide();
            <!-- or you can set CSS on these elements by:
            AJS.$('#space-tools-menu-trigger').css('visibility','hidden');
            -->
        }
    });
</script>

The above example also hides certain elements for including the quick search panel and help-menu.

You'll notice that you can also set specific element CSS just for anonymous users (see line 9).

References

  1. Atlassian's guide to custom HTML here
  2. Atlassian's excellent page for hiding elements via CSS or JS here (includes list of selector names)