The need was to redirect users to a default landing page of our site collection whenever they used "Sign in as Different User" option from any page in the application.
Following code snippet can be used which used SharePoint java script object model to get site collection URL and then replaces LoginAsAnother action method with a Source Url passing the second paramater as 1 which tells SharePoint to not append Source url (otherwise it will add the current page Url to the Source query string paramater in the URL)
<script>
function GetSiteUrl()
{
var ctx = new SP.ClientContext();
this.siteCol = ctx.get_site();
ctx.load(this.siteCol);
ctx.executeQueryAsync(Function.createDelegate(this, setLoginAsAnother), Function.createDelegate(this, onFailed));
}
function setLoginAsAnother()
{
var objects = document.getElementsByTagName("ie:menuitem");
for (var i = 0; i < objects.length; i++) {
itm = objects[i];
if ($('#' + itm.id).attr("text") == "Sign in as Different User")
{
var newurl = "\u002f_layouts\u002fcloseConnection.aspx?loginasanotheruser=true&Source=" + this.siteCol.get_url();
$('#' + itm.id).attr( "onMenuClick", "javascript:LoginAsAnother('"+newurl + "', 1)");
}
}
}
function onFailed()
{
//alert('Failed to retrieve the server relative URL.');
}
ExecuteOrDelayUntilScriptLoaded(GetSiteUrl, 'sp.js');
</script>
Following code snippet can be used which used SharePoint java script object model to get site collection URL and then replaces LoginAsAnother action method with a Source Url passing the second paramater as 1 which tells SharePoint to not append Source url (otherwise it will add the current page Url to the Source query string paramater in the URL)
<script>
function GetSiteUrl()
{
var ctx = new SP.ClientContext();
this.siteCol = ctx.get_site();
ctx.load(this.siteCol);
ctx.executeQueryAsync(Function.createDelegate(this, setLoginAsAnother), Function.createDelegate(this, onFailed));
}
function setLoginAsAnother()
{
var objects = document.getElementsByTagName("ie:menuitem");
for (var i = 0; i < objects.length; i++) {
itm = objects[i];
if ($('#' + itm.id).attr("text") == "Sign in as Different User")
{
var newurl = "\u002f_layouts\u002fcloseConnection.aspx?loginasanotheruser=true&Source=" + this.siteCol.get_url();
$('#' + itm.id).attr( "onMenuClick", "javascript:LoginAsAnother('"+newurl + "', 1)");
}
}
}
function onFailed()
{
//alert('Failed to retrieve the server relative URL.');
}
ExecuteOrDelayUntilScriptLoaded(GetSiteUrl, 'sp.js');
</script>
No comments:
Post a Comment