1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed JS-Redirecting bug

Discussion in 'Resolved Bug Reports' started by Yoskaldyr, Jun 29, 2013.

  1. Yoskaldyr

    Yoskaldyr Well-Known Member

    This function not properly worked if redirect url has a hash (file xenforo.js):
    Code:
            redirect: function(url)
            {
                url = XenForo.canonicalizeUrl(url);
    
                if (url == window.location.href)
                {
                    window.location.reload();
                }
                else
                {
                    window.location = url;
                }
            },
    
    Example:
    User fills overlay autovalidator form on page 'http://xenforo.sample.forum.com/somepage/form/'

    If XenForo Controller returns responseRedirect with url http://xenforo.sample.forum.com/somepage/form/ then browser will reload current page after form validation and submit.
    If XenForo Controller returns responseRedirect with url http://xenforo.sample.forum.com/somepage/form/#somehash then browser will stay on the same page without page reloads after form validation and submit.
     
    Last edited: Jun 29, 2013
    guiltar, nikivan, Jon W and 1 other person like this.
  2. Yoskaldyr

    Yoskaldyr Well-Known Member

    Example fix:
    Code:
    redirect: function(url)
            {
                url = XenForo.canonicalizeUrl(url);
                var hrefParts = url.split('#');
                if (hrefParts[0] == window.location.href)
                {
                    if (url != window.location.href)
                    {
                        window.location = url;
                    }
                    window.location.reload();
                }
                else
                {
                    window.location = url;
                }
            },
    
     
    chulapi likes this.
  3. Kier

    Kier XenForo Developer Staff Member

    Could you give me a specific example of a page/form/action that demonstrates the behaviour you're describing?

    Could you also let me know if you see it happening here on XenForo.com, or if it only happens on your own forum - and if it does only happen on your forum, could you describe your URL scheme - whether you're using full friendly URLs etc. Please?
     
  4. guiltar

    guiltar Well-Known Member

    I also used to deal with this issue in addons but haven't seen in the core.
    Browser doesn't redirect to url with hash only. It just shows the message in the top.

    (url == window.location.href) is always false when url includes hash since window.location.href never has hash.
     
    Yoskaldyr likes this.
  5. Mike

    Mike XenForo Developer Staff Member

    window.location.href does have a hash - at least in Chrome, FF and IE10. However, this might be an issue if you're redirecting from a page with no hash (or a different hash) to the same page with a (different) hash.
     
  6. Yoskaldyr

    Yoskaldyr Well-Known Member

    Exactly. My method fix this issue (correct redirect to the same page with different hash)
     
  7. Mike

    Mike XenForo Developer Staff Member

    It breaks other cases though (inline mod with a hash).
     
  8. Kier

    Kier XenForo Developer Staff Member

    Could you point me to a form within XenForo that would allow me to reproduce the problem you've described, or have you only had it happen with add-ons?
     
  9. Yoskaldyr

    Yoskaldyr Well-Known Member

    Maybe some additional parameter to responseRedirect or special form classname to force reload if response redirects to the same page but with different hash?
     
  10. Yoskaldyr

    Yoskaldyr Well-Known Member

    Only with addons development.
     
  11. Kier

    Kier XenForo Developer Staff Member

    I think I've altered the code to handle this now.
    Screen Shot 2013-07-03 at 12.37.42.png
     
    chulapi and Yoskaldyr like this.

Share This Page