devote / HTML5-History-API

HTML5 History API expansion for browsers not supporting pushState, replaceState
http://spb-piksel.ru
MIT License
1.02k stars 182 forks source link

Titles are not change when click browser back button #101

Open sonnety opened 8 years ago

sonnety commented 8 years ago

I follow this

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="history.js"></script>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      $(function() {
        // we get a normal Location object

        /*
         * Note, this is the only difference when using this library,
         * because the object window.location cannot be overriden,
         * so library the returns generated "location" object within
         * an object window.history, so get it out of "history.location".
         * For browsers supporting "history.pushState" get generated
         * object "location" with the usual "window.location".
         */
        var location = window.history.location || window.location;

        // looking for all the links and hang on the event, all references in this document
        $(document).on('click', 'a.ajax', function() {
          // keep the link in the browser history
          history.pushState(null, null, this.href);

          // here can cause data loading, etc.

          // do not give a default action
          return false;
        });

        // hang on popstate event triggered by pressing back/forward in browser
        $(window).on('popstate', function(e) {

          // here can cause data loading, etc.

          // just post
          alert("We returned to the page with a link: " + location.href);
        });
      });
    </script>
  </head>
  <body>
    <a class="ajax" href="/mylink.html">My Link</a>
    <a class="ajax" href="/otherlink.html">Other Link</a>
  </body>
</html>

But the Titles are not change when click browser back button.

devote commented 8 years ago

Can you explain in more detail that you do not like? And also specify which browser, version, etc.

Thanks!

sonnety commented 8 years ago

Hello i'm using chrome 51+ . And the problem is on back button with title change not working i mean see the example :

$(function() {

                     var location = window.history.location || window.location;     

                     $(document).on('click', '#ajaxlink a', function(e) {
                                var $this = this.href; 
                                history.pushState(null,null,$this); 
                                e.preventDefault();
                                return false;
                       });

                    $(window).on('popstate', function(event) {
                               document.title =  $('#gettitle').text();             
                            });

         });

All working fine but when i'm in page1 and the page title is title1 and when i click page2 and page two title is title2 so all working fine and pushState change the title properly. But the problem is in back button and i think in popstate event because when i'm in page two and when i back to page1 then the title not changing to title1, i mean title2 > title1 . I think u understand.