Is there a way to add an Custom Redirect inside my Publishing Site Collection on sharepoint online 2013
-
11-12-2020 - |
Domanda
when i was working on enterprise wiki site collection inside an on-premise deloyment, i use to add the following code inside a farm solution, then add the generated custom WebPart to my enterprise wiki home page:-
public class CustomWikiPageBase : PublishingLayoutPage
{
protected override void OnInit(EventArgs e)
{
if (!String.IsNullOrEmpty(Request.QueryString["TreeField"])
&& !String.IsNullOrEmpty(Request.QueryString["TreeValue"]))
{
Response.Redirect(String.Format("{0}?TreeField={1}&TreeValue={2}",
SPContext.Current.ListItem.ParentList.DefaultViewUrl,
Request.QueryString["TreeField"],
Request.QueryString["TreeValue"]));
}
else if (!String.IsNullOrEmpty(Request.QueryString["TreeField"]))
{
Response.Redirect(String.Format("{0}?TreeField={1}",
SPContext.Current.ListItem.ParentList.DefaultViewUrl,
Request.QueryString["TreeField"]));
}
base.OnInit(e);
}
}
as mentioned in this link Link. The reason to include this method, is to allow metadata navigation inside the Tree view. i did this appraoch on 3 on-premise deployment and they worked well.
but now i am working on sharepoint 2013 online. so can anyone adivce how i can add the above method, or similar method? as i mentioned inside the on-premise i use to add this method inside a farm solution,and farm solutions is not an option inside SP online ?
I mean can i use the same logic from my above method,inside a JSOM or any other script which i can use inside SP online to do the redirect ?
Soluzione
Use a Script Editor WebPart on your desired Page, put following Code into it (or create a Sandboxed No Code Solution WebPart using Visual Studio)
<script>
var treeField = GetUrlKeyValue("TreeField");
var treeValue = GetUrlKeyValue("TreeValue");
if(treeField && treeValue){
window.location = "http://contoso.com?TreeField="+treeField+"&TreeValue="+treeValue;
}
</script>
If you need a dynamic URL of your List you can access the _spPageContextInfo Object and parse the listview URL out (for example _spPageContextInfo.serverRequestPath will give you the URL to the form eg.: "/sites/Listname/Forms/DispForm.aspx")
More to Read: http://social.technet.microsoft.com/wiki/contents/articles/29766.sharepoint-understanding-the-sppagecontextinfo-object.aspx https://stackoverflow.com/questions/4744751/how-do-i-redirect-with-javascript https://praneethmoka.wordpress.com/2012/01/12/some-useful-javascript-variablesfunctions-in-sharepoint/