You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tumblr主题自定义:文章页添加返回上一页链接问题求助

Fixing the Back-to-Previous-Page Link on Your Tumblr Post Page

Hey there! Let's get that back-to-previous-page link working properly for your custom Tumblr theme. I see you've tried a couple of approaches, so let's break down what's going wrong and how to fix it.

Why Your Current Code Isn't Working

  • Your first link (<a class="acme-post-return -hide-index" href="/">← Back to {Title}</a>) always redirects to your blog's homepage, not the actual previous page the user came from. That's why it doesn't match the behavior you want.
  • Your second link has a syntax issue in the onclick attribute—you're missing proper quoting around the JavaScript, which breaks the functionality. Even if fixed, relying solely on document.referrer can be unreliable (it might be empty if the user landed directly on the post page, for example).

The Reliable Solution

Use the browser's built-in window.history.back() method, which directly navigates to the previous page in the user's browsing history. Here's the corrected code:

<a class="acme-post-return -hide-index" onclick="window.history.back(); return false;" href="/">← Go to Previous Page</a>

What This Does:

  • window.history.back() tells the browser to go back one page, just like clicking the browser's back button.
  • return false; prevents the default link behavior (which would take the user to / if the JavaScript fails).
  • The href="/" acts as a fallback, so if for some reason the history back doesn't work (e.g., the user opened the post in a new tab), they'll still land on your homepage.

Bonus: Add a Fallback for Empty History

If you want to make it even more robust (for users who land directly on the post page with no browsing history), you can check if there's a previous page to go back to:

<a class="acme-post-return -hide-index" onclick="
  if (window.history.length > 1) {
    window.history.back();
  } else {
    window.location.href = '/';
  }
  return false;
" href="/">← Go to Previous Page</a>

Quick Check

Make sure this code is placed within your Tumblr theme's post page template (usually inside the {block:PermalinkPage} block) so it only shows up when someone is viewing an individual post. Your existing -hide-index class should already handle hiding it on the homepage, which is perfect.

内容的提问来源于stack exchange,提问作者Lorento L

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:39:43