My problem is that I want to redirect via JavaScript to a directory above.

My code:

location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'))

The URL looks like this:

example.com/path/folder/index.php?file=abc&test=123&lol=cool

The redirect affect just this:

example.com/path/&test=123&lol=cool

But want to have this:

example.com/path/

How can I do it?

7 Answers
7

You can do a relative redirect:

window.location.href="https://stackoverflow.com/questions/1655065/"; //one level up

or

window.location.href="https://stackoverflow.com/path"; //relative to domain

Leave a Reply

Your email address will not be published. Required fields are marked *