we will see how to add a menu option in Office 365 SharePoint site. We can add the menu option on the top right corner of the Settings page or as a navigation on the site’s Setting link.
Let’s see how we can add the menu action using script.
- Open your site
- Go to Edit Page by clicking on the Settings gear in the top-right corner
- Click on Check Out
- You will see the Edit page of the site
- Click on “INSERT” under Media and Content and add "Script Editor".
- Open the Script Editor and paste the code given below.
- Code Snippet
- <script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
- <script language="javascript" type="text/javascript">
- $(document).ready(function() {
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddSettingsMenuAction);
- });
- function AddSettingsMenuAction() {
- //Read the web
- var clientContext = new SP.ClientContext();
- var oWeb = clientContext.get_web();
- //Add the new custom action
- var collMenuAction = oWeb.get_userCustomActions();
- var menuAction = collMenuAction.add();
- menuAction.set_location('Microsoft.SharePoint.StandardMenu');
- menuAction.set_sequence(101);
- menuAction.set_group('SiteActions');
- menuAction.set_title("My Home");
- menuAction.set_url("https://sharepointworldbymanpreet.wordpress.com/");
- menuAction.update();
- //Load the group details and execute
- clientContext.load(collMenuAction);
- clientContext.executeQueryAsync(ScriptSuccess, ScriptFailure);
- }
- //Log Success Details
- function ScriptSuccess() {
- console.log("Menu Added");
- }
- //Log Failure Details
- function ScriptFailure() {
- console.log(args.get_message());
- }
- </script>
- Click on OK.
- You will see a “My Home” menu button attached to your menu option.
Using this script, you can add the menu items of your choice for all the users who will access the SharePoint sites.
No comments:
Post a Comment