Reputation: 6264
My application is a single page application ,I am using links like shown below
<a class="list-group-item navigationlink" href="#" id="roletemplates-link" data-moduleid="2">Role Templates</a>
You can see that href="#"
. On clicking that link I use ajax to load content to the page.
I want to append "#" to URL when I click that link without reloading the page. In many solutions I saw is like that the page will have to be reloaded if we want to append some values to variables.
My Question:
Is it possible to append the "#" to URL on clicking the link without reloading the page?
Upvotes: 1
Views: 1466
Reputation: 1569
It is very much possible that you can append # to the url.
Now the url can be same or different.
In case of same url:
It won't refresh the page at all. Instead, it will search for the fragment identifier in the same and it will scroll to that portion of the page.
In case of different url:
It will reload the page and scroll to the portion of the page for which fragment identifier is mentioned after the #.
Hope that this answers your question.
Upvotes: 0
Reputation: 305
Save your string '#' or anything in a hidden element and add it in the url directly by adding a function on onclick.
hope it works.
Upvotes: 0
Reputation: 1559
This can be done via Javascript:
window.location.hash = "myfancynewhashtag";
Upvotes: 3