I have created grid view page. When I go click on one specific grid its display content of that grid. Now I want to put one 'back' link in side the page of content, that back link displays main view page.

  • It's amazing how so simple task can sometimes be so hard to figure out. To be honest, it's not google-able now as far as I can test, so please don't close due to lack of research.
    – Mołot
    Oct 25, 2013 at 7:07
  • Does this view displays items from a single content type? or from all content type?
    – Gladiator
    Oct 25, 2013 at 7:21
  • I'm struggling to understand where the complexity is here - you want to add a link to a certain URL, on the full view page of a specific content type? What's wrong with creating a template file for that specific node type, and simply adding the link in HTML? If you're trying to get the link to appear only if the content page has been visited as a result of clicking on one of the grids in the View, I'd suggest you might be approaching your build wrongly - it's easy to argue that displaying different content based on HTTP referrer violates the fundamental stateless nature of HTTP
    – Clive
    Oct 25, 2013 at 8:24
  • It's unclear what the setup of the OP is, what's displayed in the listing page, how many listing pages he has, if one node can be on different listing pages etc. -1
    – Beebee
    Oct 25, 2013 at 8:38
  • 1
    @MPD Yeah, I understand a lot of people wind up in these 'discussions' with clients (I know I do). As far as I'm concerned the technicality wins every time - providing different breadcrumbs/back-links based on the HTTP referrer violates HTTP. The most sensible solution is to inject a JS history link and be done with it, I think
    – Clive
    Nov 28, 2013 at 14:35

3 Answers 3


Though they seem rather simple, "back" links on pages are rather tricky. For the sake of this post, lets assume that you have a shopping site with a search page, and item detail pages.

One complication arises from the fact that users can arrive on the item detail page from multiple paths, including from Google and other pages that aren't in your site. The back link really only makes sense when they have come from the search results page.

Another complication comes from how Drupal handles page caching. You could potentially render a back link on a page, but unless you take some URL parameter into account (to have a different $cid), users may see the wrong cached page. However, if you do tack on a back= to the URL parameter, you now severely lower the probability that a user will actually get a page from the cache.

I have mostly settled on Javascript based solutions. There are two main options. All are real variants on each other. On the detail page, you jQuery in a link that goes back to the search results.

One way is to jQuery some logic on the search results page that sets a cookie with the exposed filer values, URL, or something similar. Then on the detail page, you use this to go back. However, this does not work cross-window / cross-tab, and there are security implications with building links this way.

The second way (and the way I have been using lately) just jQueries in a link on the item detail page that calls window.history.back(). This also isn't ideal, but it tends to be the least bad solution.


I would use the javascript solution (window.history.back()), because it's easy to implement.

You could add a php check to display or not the button to be sure you're coming from your website, and not from a Google search for example.

For this, check the $_SERVER['HTTP_REFERER'] variable. If it matches your DNS, then you display the link, otherwise not.

  • Hi Matt,would be possible to write the full code here including the $_SERVER check?I am not so experienced.Thanks!
    – Dion
    Mar 19, 2015 at 17:27

In the content for which you have created a grid view page
add a link field which will point to view page.

So eventually this Link field will be displayed when u see the view of particular content .So you can click on this link which will act as Back Link . You can hide the link field in the grid view page by css .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.