我的问题是我想通过 JavaScript 重定向到上面的目录。
我的代码:
location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'))
网址如下所示:
example.com/path/folder/index.php?file=abc&test=123&lol=cool
重定向只影响这个:
example.com/path/&test=123&lol=cool
但是想拥有这个:
example.com/path/
我该怎么做?
最佳答案
你可以做一个相对重定向:
window.location.href = '../'; //one level up
或
window.location.href = '/path'; //relative to domain
关于javascript - 重定向到 JavaScript 中的相对 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1655065/