In my javascript code I want to be able to retrieve current URL and then generate a new URL by adding relative paths (all of this without actually redirecting to new place, just want the URL string reference to pass on).
For eg: - this is exactly what I want but minus the redirection that kicks in
window.location.href = "../../";
var url = window.location.href;
I just want the result of appending relative path to current url and retrieve the new URL in string format.
EDIT with example to make the question more clear.
Suppose the current URL is:
www.example.com/level1/level2/level3/index.html
Now I want to get the URL 2 levels back:
www.example.com/level1