Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Titles are not change when click browser back button #101

Open
sonnety opened this issue Jul 1, 2016 · 2 comments
Open

Titles are not change when click browser back button #101

sonnety opened this issue Jul 1, 2016 · 2 comments

Comments

@sonnety
Copy link

sonnety commented Jul 1, 2016

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
Copy link
Owner

devote commented Jul 1, 2016

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

Thanks!

@sonnety
Copy link
Author

sonnety commented Jul 1, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants