Hans.Gundlach
Hans.Gundlach

Reputation: 431

Javascript Page reroute

We are making a chat web app using JavaScript where we store the user session in a cookie. One of our pages requires a user to enter in his or her username and then press Go to be redirected to a chat room. The store values function is being called by a button. It in turn calls the SetCookie funtion, which calls the redirect. However our button does not redirect them to the next page.

function setCookie(name, value){
        document.cookie=name + "=" + escape(value) + ", path=/; expires=" + expiry.toGMTString();
        console.log(document.cookie+"hello");
        var url = "file:///C:/Users/Admin/Documents/Mathworks/Lobby.html";    
        window.location.replace("file:///C:/Users/Admin/Documents/Mathworks/Lobby.html");
    }
    console.log(document.cookie);
    //this should set the UserName cookie to the proper value;
    function storeValues(form)
    {
        setCookie("userName", document.getElementById("inputBox").value);
        console.log(document.cookie+"word");
        return true;
    }

Upvotes: 1

Views: 28

Answers (1)

georgiaboy82
georgiaboy82

Reputation: 552

It is document.location.replace(), not window.location.replace(). You could also try document.location.assign(url).

Upvotes: 1

Related Questions