使用 jQuery Address 更改后退按钮上的页面标题

发布于 2024-12-22 07:54:36 字数 421 浏览 2 评论 0原文

利用 jQuery Address 启用浏览器的后退按钮,我能够利用插件的事件“onExternalChange”来检测浏览器何时实际点击后退按钮,以便我也可以触发页面标题更改。不幸的是,我无法让它抓住当前部分,因为它在跳跃之前抓住它,因此每次都是一次:

$.address.externalChange(function() {
    var lastPageTitle = 'Kevin Dare Foundation | ' + $('nav').find('.active').html();
    $.address.title(lastPageTitle);
});

链接: http://nickdimatteo.com/kjd

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);
});

link: http://nickdimatteo.com/kjd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独闯女儿国 2024-12-29 07:54:36

看起来以下问题可以解决:

//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');
  }
});

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');
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文