문제

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();

}

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top