Utilizing jQuery Address to enable the browser's back button, I was able to leverage the plugin's event "onExternalChange" to detect when the browser actually hits the back button, so that I could trigger the page title to change on that as well. Unfortunately I can't get it to grab the current section, as it grabs it before it jumps, thus being one off everytime:
$.address.externalChange(function() {
var lastPageTitle = 'Kevin Dare Foundation | ' + $('nav').find('.active').html();
$.address.title(lastPageTitle);
});
Looks like the following solves the problem:
//Change Page Title on browser back button press
$.address.externalChange(function() {
var hash = document.location.hash.replace(/^#\//, '');
var lastPageTitle = 'Kevin Dare Foundation | ' + $('nav a[href="#'+hash+'"]').html();
if(hash) {
$.address.title(lastPageTitle);
}
else //account for no hash
{
$.address.title('Kevin Dare Foundation');
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.