I am creating a script for listening to browser back button and loading the previous page. I am new to jquery and javascript (a php person). Before re inventing this, I have searched the whole web for a library. But as I am using a lot of parameters in my ajax links, I cant use those libraries. I admit its my mistake, because I dont know how to use such complex systems. So I am thinking if creating a system as follows.
// get the contents of a particular div and save as an object/associative array
// { hash : pageNumber, html : content}
function save_history(div){
var content = $(div).html();
// increment the page number and add hash tags to the URL
}
// Listen to the browser hash value change
$(window).bind('hashchange', function () {
hash = window.location.hash;
if(hashValue){
load_history(hashValue);
}
});
// Load data from history
function load_history(id){
// fetch the content based on the hashvalue
$(div).html(content);
}
Is there any problem in using this? Will this make the pages unresponsive or crash the browser, when a lot of contents are saved as objects? I dont want to waste my time if it causes such problems.
Seems like pjax is the library you're looking for: https://github.com/defunkt/jquery-pjax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With