Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • J 351 posts 606 karma points
    Feb 17, 2014 @ 19:49
    J
    0

    How to redirect to a webpage

    I am using this link http://www.it-potato.com/2013/07/adding-a-custom-section-in-umbraco-6/ to create a custom section, which ive completed.

    I would now like to create individual folders (when the user accesses this section) so when they click each folder they are redirected to a specific webpage within the site. How do i do this?

  • Dan Lister 416 posts 1973 karma points c-trib
    Feb 18, 2014 @ 11:57
    Dan Lister
    0

    How about something similar to your example link but changing the following methods? You could replace your myObjects collection with Umbraco Content objects.

    public override void Render(ref XmlTree tree)
    {
        IEnumerable myObjects = (new MyRepository()).GetAllObjects();
        foreach (MyObject o in myObjects) 
        {
            XmlTreeNode node = XmlTreeNode.Create(this);
            node.NodeID = b.Id.ToString();
            node.Text = b.Name;
            node.Icon = FolderIcon;
            node.Action = String.Format(“openNodeUrl({0})”, b.Url);
            tree.Add(node)
        }
    }
    public override void RenderJS(ref StringBuilder Javascript)
    {
        Javascript.Append(@"
            function openNodeUrl(url) {
                window.location = url;
            }
        ");
    }
    
  • J 351 posts 606 karma points
    Feb 19, 2014 @ 11:24
    J
    0

    [quote]You could replace your myObjects collection with Umbraco Content objects.[\quote]

     

    Thanks. I dont have any content objects to load (unless ive picked the wrong approach) but ideally i would like to have a few folders so when a user clicks one of these folders they are presented with a page within my site. Therefore i did the below 

     

            public override void Render(ref XmlTree tree)

            {

            XmlTreeNode node = XmlTreeNode.Create(this);

            node.NodeID = "1";

            node.Text = "Some text";

            node.Icon = FolderIcon;

            node.Action = String.Format("openNodeUrl({0})", "http://localhost/mysite/mypage.aspx");

            tree.Add(node);

            }

     

    but doesnt work?

  • Dan Lister 416 posts 1973 karma points c-trib
    Feb 19, 2014 @ 11:36
    Dan Lister
    0

    Does your "Some text" node appear in your custom tree? If so, are there any console errors when clicking the node?

  • J 351 posts 606 karma points
    Feb 20, 2014 @ 16:16
    J
    0

    I have the SomeText node appearing but when clicking this folder it doesnt redirect me to a webpage within my site? So all im after now is when the SomeText folder is clicked it needs to open up a page. Thanks

  • Dan Lister 416 posts 1973 karma points c-trib
    Feb 20, 2014 @ 18:02
    Dan Lister
    0

    Are there any console logs in your browser after clicking the node?

  • J 351 posts 606 karma points
    Feb 20, 2014 @ 20:51
    J
    0

    Im not sure what you mean by console Logs? What i am expecting to happen is when i click this folder it would open up http://localhost/mysite/mypage.aspx. No errors are listed when clicking the Some text folder.

  • Dan Lister 416 posts 1973 karma points c-trib
    Feb 21, 2014 @ 09:36
    Dan Lister
    0

    If you are using Google Chrome, take a look at their documentation on how to access the browser's console logs. The reason I ask is to find out whether or not there are any JavaScript errors present when clicking your folder node.

  • J 351 posts 606 karma points
    Feb 21, 2014 @ 11:55
    J
    0

    There are a few errors but non that should create this problem i would believe

     

    body.scrollTop is deprecated in strict mode. Please use 'documentElement.scrollTop' if in strict mode and 'body.scrollTop' only if in quirks mode. DependencyHandler.axd?s=L3VtYnJhY29fY2xpZW50L0FwcGxpY2F0aW9uL05hbWVzcGFjZU1hbmFnZXIuanM7L3VtYnJhY29…:6

    body.scrollLeft is deprecated in strict mode. Please use 'documentElement.scrollLeft' if in strict mode and 'body.scrollLeft' only if in quirks mode. DependencyHandler.axd?s=L3VtYnJhY29fY2xpZW50L0FwcGxpY2F0aW9uL05hbWVzcGFjZU1hbmFnZXIuanM7L3VtYnJhY29…:6

    event.returnValue is deprecated.

     

    What i noticed is the URL when i hover over the folder to be in this format:

     

    http://localhost:1234/umbraco/openNodeUrl(http://www.mysite.com)

     

    thats after the Action is set to

     

    node.Action = String.Format("openNodeUrl({0})", "http://www.mysite.com");

     

    and that doesnt work so internal links wont work either?

  • Dan Lister 416 posts 1973 karma points c-trib
    Feb 21, 2014 @ 12:00
    Dan Lister
    100

    Try changing the node action to:

    node.Action = String.Format("javascript: openNodeUrl('{0}')", "http://www.mysite.com");
  • J 351 posts 606 karma points
    Feb 21, 2014 @ 17:29
    J
    0

    i changed it to String.Format("openNodeUrl(\'{0}\')", "http://localhost/mysite/mypage.aspx"); which did the trick. However i have kept your code just in case i get an issue down the line - thanks

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies