共用方式為


SP.UserCustomAction Class

Applies to: SharePoint Foundation 2010

Represents a custom action associated with a SharePoint list, Web site, or subsite.

SP.UserCustomAction

Inherits

SP.ClientObject Class

Example

The following example creates an input button on an application page that adds a new menu item to the Site Actions menu of the current website.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

function runCode() {
    var clientContext = new SP.ClientContext();
    var site = clientContext.get_web();
    var UserCustomActions = site.get_userCustomActions();

    var newUserCustomAction = UserCustomActions.add();
    newUserCustomAction.set_location('Microsoft.SharePoint.StandardMenu');
    newUserCustomAction.set_group('SiteActions');
    newUserCustomAction.set_sequence(1000);
    newUserCustomAction.set_title('New Menu Item');
    newUserCustomAction.set_imageUrl('/_layouts/images/myIcon.jpg');
    newUserCustomAction.set_description('Menu item added via ECMAScript');
    newUserCustomAction.set_url('/_layouts/create.aspx');
    newUserCustomAction.update();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {
    alert('New menu item added to Site Actions menu.\n\nTo view the new menu item, refresh the page.');
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

See Also

Reference

SP.UserCustomAction Methods

SP.UserCustomAction Properties

SP Namespace