Question

I have java script function to check the URL and split it, I ask a question and depends on the answer it will forward the user page all works fine until I use window.location.assign(); with string inside (=window.location.assign(path);) instead of fixed URL (=window.location.assign("http://stackoverflow.com");) what can i do? thanks...

var register=...;
var login=...;
function link(type) {
var urlPath = document.URL.split("/");
if (type == "register") {
    var path= urlPath[2] + register;
    window.location.assign(path);
}
else {
    var path = urlPath[2] + login;
    window.location.assign(path);

}
event.preventDefault();

}

Was it helpful?

Solution

You should use the full URL.

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+register);

window.location.assign(urlPath[0]+'/'+urlPath[1]+'/'+urlPath[2]+path);

Or

window.location.assign(window.location.origin+register);

window.location.assign(window.location.origin+path);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top