Please help me understand why my code does not redirect to a specific link.

On the page there is something like this script (I quote a part)

console.log(hostnameStr); // '' console.log(pathStr); // '/brands' console.log(brandStr); // '/BlackBerry' alert(hostnameStr + pathStr + brandStr); document.location.href = hostnameStr + pathStr + brandStr; 

Before this code, I define hostnameStr , pathStr , brandStr . Then, as you can see, I bring them to the console and to the modal window. At the same time the address is shown correct

But the last line redirects to about that address. 

According to my idea, the redirection should occur at such an address. 

    2 answers 2

    document.location , window.location


     document.location=''+hostnameStr + pathStr + brandStr;

    and considering

    document, localization was not a property, although it is a gecko browser. For cross-browser safety, use window.location instead.

    will be better

      window.location=''+hostnameStr + pathStr + brandStr; 

      Redirect without host:

       document.location.href = pathStr + brandStr; 
      • one
        it is yes but I would like to understand the reason. The question in this was - cyklop77