我有一个问题:我想通过 JavaScript 重定向到上面的目录。我的代码:
location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'));
URL 如下所示:
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