Search code examples
phpjavascriptjqueryhashchange

Saving AJAX page state


Is there any way to listen for hashchanges in the url and log the event for use of a backbutton in AJAX etc.

Using links like such:

<a href="/#!page">Go to page!</a>

and script like this:

<script type="text/javascript">

    $(function () {
        if (window.location.hash){contentload(window.location.hash);}

        $('a').click(function() {
            fragment = this.hash;
            contentload(fragment);
        });

    });

    function contentload(fragment) {
        fragment = fragment.slice(1).replace('!', '')
        $('#content').load('http://mysite.com/'+fragment+'?ajax=1');
    }

</script>

I need to try and save the state of the page, Ive seen the jQuery address plugin but have no idea how to implement this..


Solution

  • i solved this using the jQuery Address plugin