Skip to content
Advertisement

window.history.pushState function reloads the page when used

i am trying to go from page to page without reloading, i read on other questions that i can use

    window.history.pushState()

to not reload the page, but it is still reloading the page.

i also tried using this function but kept giving me a syntax error

  function changeurl(url, title) {
   var new_url = '/' + url;
   window.history.pushState('data', 'Title', new_url);
   document.title = title;
    }

the syntax error occurs and it reads: “unexpected token ,”

here is an example of my HTML:

 <a class="ac" href=""  onclick="window.history.pushState('data', 'Title', 'index?a=recieved');"></a></td>
        <li>

         <a class="" href="index?b=favorites" onclick=""></a></td>
        </li>
        <li>
           <a class="" href="index?a=sent" onclick=""></a></td>
        </li>

what can i do to get my pages not to reload?

Advertisement

Answer

Try this href=”javascript:void(0)” in tag a

<a class="ac" href="javascript:void(0)"  
onclick="window.history.pushState('data', 'Title', 'index?a=recieved');">
Link
</a>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement