First. My way:
javascript:window.location = _spPageContextInfo.siteAbsoluteUrl + '/_layouts/closeConnection.aspx?loginasanotheruser=true' + '&Source=' + window.location;
Second. CSOM. I think this is not better solution because we have at least one request to server via executeQueryAsync just to get web url:
(function () {
var ctx = new SP.
(
Read more... )