用于在快速启动中填充页面的Java脚本

时间:2017-11-02 20:12:09

标签: sharepoint sharepoint-online

我正在使用wiki网站。我想知道是否有办法填充从页面库创建的页面自动添加到快速启动?否则每次我都会从导航中手动添加它们。

如果是,我可以使用示例代码吗?

1 个答案:

答案 0 :(得分:2)

请参阅以下代码示例,了解如何使用javascript添加快速启动链接。

这是工作代码。您可以根据需要修改此代码并直接使用。

var quickLaunchNodeCollection = null;
var oNewNaviNode = null;

function addNavigationNodes() {

    var context = new SP.ClientContext.get_current();

    if (context != undefined && context != null) {

        var web = context.get_web();

        //this.navigationNodeCollection = web.get_navigation().get_topNavigationBar();
        this.quickLaunchNodeCollection = web.get_navigation().get_quickLaunch();

        // Set properties for a new navigation node.
        this.oNewNaviNode = new SP.NavigationNodeCreationInformation();
        oNewNaviNode.set_title("NewNavigationNode");
        oNewNaviNode.set_url("http://www.google.com");

        oNewNaviNode.set_asLastNode(true);
        this.quickLaunchNodeCollection.add(oNewNaviNode);

        context.load(this.quickLaunchNodeCollection);
        context.executeQueryAsync(addNavigationNodesSuccess, addNavigationNodesFailed);
    }
}

function addNavigationNodesSuccess() {
    alert("New node added...");
}

function addNavigationNodesFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
相关问题