Fixed JS-Redirecting bug

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:
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;
            }
        },
 
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?
 
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.
 
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.
 
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.
Exactly. My method fix this issue (correct redirect to the same page with different hash)
 
Exactly. My method fix this issue (correct redirect to the same page with different hash)
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?
 
Top Bottom