I'm exploring the possibility of updating URLs using JavaScript alone, by refreshing content through AJAX.
This approach aims to avoid the unwanted side effects of traditional page refreshes, such as interrupting music playback or clearing input fields like chat messages.
- Stopping the current music playback
- Losing unsaved work, such as typed messages
I've recently started experimenting with this concept and here's what I have so far:
var links = document.querySelectorAll('a');
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('click', function(event){
event.preventDefault();
});
}
return false;
However, there are a couple of issues with this code:
- The URL doesn't get updated
- AJAX content is not loaded
My question is: how can I prevent the page from refreshing but still allow the URL to be changed?