Reputation: 21
I need a button, which lead up in url path like this:
from /host/elements/1
to /host/elements
I have a link in my html:
<a href="javascript:go_backward()"> </a>
And a javascript function:
function go_backward() {
var url = window.location.href;
var page = url.substring(0, url.lastIndexOf('/'))
window.location.assign(page);
return false;
}
But when i click the button i only get desired url printed, without correct redirect. Why cat it be so?
Upvotes: 0
Views: 36
Reputation: 2518
Change:
window.location.assign(page);
return false;
to
window.location.href = page;
If you just want to go back you can also use:
window.history.go(-1)
Upvotes: 1