Append a new menu item

Append a new menu item to the SiteAction menu:

var siteActionMenuId = 'zz1_SiteActionsMenuMain';
var siteActionMenu = new SPMenu(siteActionMenuId);

var newItem = new SPMenuItem();
newItem.Title = "New Item";
newItem.Type = "option";
newItem.OnClick = "alert('Hello world!');";

siteActionMenu.AddItem(newItem);
siteActionMenu.LargeIconMode = false;
siteActionMenu.Update();

Append a new SubMenu

Create submenu and append it to the SiteAction menu:

var siteActionMenuId = 'zz1_SiteActionsMenuMain';
var siteActionMenu = new SPMenu(siteActionMenuId);

var newSubItem = new SPMenuItem();
newSubItem.Title = "New SubMenu Item";
newSubItem.Type = "submenu";

for(var i = 0; i < 10; i++){
    var item = new SPMenuItem();
    item .Title = "Item " + i;
    item .Type = "option";
    item.OnClick = "alert('" + i + "')";
    newSubItem.Items.push(item);
}

siteActionMenu.AddItem(newSubItem);
siteActionMenu.LargeIconMode = false;
siteActionMenu.Update();






Last edited May 30, 2012 at 6:06 AM by VitalyZhukov, version 4

Comments

No comments yet.