I have a problem:
location.href = (location.href).substr(0, (location.href).lastIndexOf(‘folder’));
The URL looks like this:
The redirect affect just this:
But want to have this:
How could I do that?
You can do a relative redirect:
window.location.href = '../'; //one level up
window.location.href = '/path'; //relative to domain
If you use
location.hostname you will get your domain.com part. Then
location.pathname will give you /path/folder. I would split
location.pathname by / and reassemble the URL. But unless you need the querystring, you can just redirect to
.. to go a directory above.
<a href="..">no JS needed</a>
.. means parent directory.
window.location.assign("../");// one level up
window.location.assign("/path");// relative to domain