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"]))
        else if (!String.IsNullOrEmpty(Request.QueryString["TreeField"]))

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 ?


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)


   var treeField = GetUrlKeyValue("TreeField");
   var treeValue = GetUrlKeyValue("TreeValue");

   if(treeField && treeValue){
      window.location = "http://contoso.com?TreeField="+treeField+"&TreeValue="+treeValue;


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/

  • your code will work if i remove this if(treeField){ window.location = "http://contoso.com?TreeField="+treeField; } i am not sure why you added ? thanks – john Gu Nov 15 '16 at 15:57
  • 1
    I just coded a quick sample based on your requirements. you had the same check above – t0. Nov 15 '16 at 16:02
  • ya i know , but i have to remove the if(treeField){ window.location = "http://contoso.com?TreeField="+treeField; } for it to work... not sure why . – john Gu Nov 15 '16 at 16:52
  • 1
    Sure. I removed the last statement – t0. Nov 16 '16 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.