SP.Web.getSubwebsForCurrentUser(query_) Method

SharePoint 2010

Last modified: May 27, 2011

Applies to: SharePoint Foundation 2010

In this article
Return Value
Applies To

Returns the collection of child sites of the current site based on the specified query.

var value = SP.Web.getSubwebsForCurrentUser(query_);


Specifies which child sites to return.

Type: SP.SubwebQuery

If the query is not valid, the server must return an empty collection.

The following example creates an input button on an application page that displays the titles of the child sites of the current site.

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

    var webCollection = null;
    function runCode() {

        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var web = clientContext.get_web();

            this.webCollection = web.getSubwebsForCurrentUser(null);

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    function onQuerySucceeded() {
        var webInfo = 'Child sites of the current site: \n\n';
        var webEnumerator = this.webCollection.getEnumerator();
        while (webEnumerator.moveNext()) {
            var web = webEnumerator.get_current();
            webInfo += web.get_title() + '\n';

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


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