For modify the URL without reloading the page we can use:
window.history.pushState('page2', 'Title', '/page2.php');
but if I try it with <a>
element :
<a onClick='my_function()' href='/page2.php'> Click Here </a>
<script>
function my_fnuction(){
window.history.pushState('page2', 'Title', '/page2.php');
}
</script>
It will not work, So how can I use <a>
element and window.history.pushState()
together?
Like twitter and Facebook, user can click on the right button to open the URL in new window, and direct click to get pages and change the URL without reloading