Skip to main content
deleted 48 characters in body
Source Link

Finally I get a fully worked solution on each site in SharePoint.

It needs to be pasted in default.aspx under the tag:

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Here is the js code:

<script type = "text/javascript" >

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.load(this.webCollection);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
}
    
function onQuerySucceeded() {
    var webName = "";
    var webEnumerator = this.webCollection.getEnumerator();
    webEnumerator.moveNext();
        var web = webEnumerator.get_current();
        webName += web.get_titleget_url(); 
    window.location.href = "http://sharepoint/sites/sitename/" + webName;
}

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

            
</script>   

IMPORTANT!

I must notice that first subsite is the first created subsite.

If somebody moves the hyperlinks in top navigation bar, it doesn't matter for above redirection method - it always moves to the first created (by admin or developer) subsite!

Finally I get a fully worked solution on each site in SharePoint.

It needs to be pasted in default.aspx under the tag:

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Here is the js code:

<script type = "text/javascript" >

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.load(this.webCollection);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
}
    
function onQuerySucceeded() {
    var webName = "";
    var webEnumerator = this.webCollection.getEnumerator();
    webEnumerator.moveNext();
        var web = webEnumerator.get_current();
        webName += web.get_title(); 
    window.location.href = "http://sharepoint/sites/sitename/" + webName;
}

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

            
</script>   

IMPORTANT!

I must notice that first subsite is the first created subsite.

If somebody moves the hyperlinks in top navigation bar, it doesn't matter for above redirection method - it always moves to the first created (by admin or developer) subsite!

Finally I get a fully worked solution on each site in SharePoint.

It needs to be pasted in default.aspx under the tag:

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Here is the js code:

<script type = "text/javascript" >

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.load(this.webCollection);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
}
    
function onQuerySucceeded() {
    var webName = "";
    var webEnumerator = this.webCollection.getEnumerator();
    webEnumerator.moveNext();
    var web = webEnumerator.get_current();
    webName += web.get_url(); 
    window.location.href = webName;
}

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

            
</script>   

IMPORTANT!

I must notice that first subsite is the first created subsite.

If somebody moves the hyperlinks in top navigation bar, it doesn't matter for above redirection method - it always moves to the first created (by admin or developer) subsite!

Source Link

Finally I get a fully worked solution on each site in SharePoint.

It needs to be pasted in default.aspx under the tag:

<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">

Here is the js code:

<script type = "text/javascript" >

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.load(this.webCollection);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }
}
    
function onQuerySucceeded() {
    var webName = "";
    var webEnumerator = this.webCollection.getEnumerator();
    webEnumerator.moveNext();
        var web = webEnumerator.get_current();
        webName += web.get_title(); 
    window.location.href = "http://sharepoint/sites/sitename/" + webName;
}

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

            
</script>   

IMPORTANT!

I must notice that first subsite is the first created subsite.

If somebody moves the hyperlinks in top navigation bar, it doesn't matter for above redirection method - it always moves to the first created (by admin or developer) subsite!