[javascript] Change URL without refresh the page

I would like to replace an url without page refresh.

I need to change:

https://example.com/en/step1

to

https://example.com/en/step2

How to do that ?

This question is related to javascript html5-history

The answer is


When you use a function ...

<p onclick="update_url('/en/step2');">Link</p>

<script>
function update_url(url) {
    history.pushState(null, null, url);
}
</script>