Reputation: 1376
I am trying to remove #step_4#step_4#step_4
from my local
project link
https://localhost/test-project/#step_4#step_4#step_4
using window.location.href
.
I have done below code for that
var url_id = window.location.href;
var url_id_value = url_id.split('#')[1];
console.log(url_id.split('#')[1]);
But I just got step_4
in console.
But I want to store a value https://localhost/test-project/
in variable using window.location.href
or is there any other way to store that value in variable?
Upvotes: 0
Views: 198
Reputation: 525
Replace the line of code var url_id_value = url_id.split('#')[1];
with the following:
var url_id_value = url_id.substr(0, url_id.lastIndexOf("/") + 1);
Upvotes: 1