3

In a Django template, the following takes me to the referring page:

<a href="{{ request.META.HTTP_REFERER }}">Referring Page</a>

But if I were using anchor tags, and the referring page was http://example.com/example/#section7, {{ request.META.HTTP_REFERER }} wouldn't contain the anchor information.

Is there a way I can alter {{ request.META.HTTP_REFERER }} (for instance, in my views.py) such that the anchor tag information is preserved?

manniL
  • 7,157
  • 7
  • 46
  • 72
Hassan Baig
  • 15,055
  • 27
  • 102
  • 205

1 Answers1

1

No, because the anchor # value is never transferred to the server side. Its is purely a client site thing to jump to defined parts of a page.

Somewhat unrelated: that is why, years ago, Google came up with the #!, an anchor marker that the Google bot would spider, instead of ignore like the regular # value. The biggest user for that was Twitter, iirc. With Javascript's pushstate() becoming a thing, the #! got forgotten.

Back on topic, the server will never know about any # or #! values, and thus the HTTP_REFERER will not contain it.

C14L
  • 12,153
  • 4
  • 39
  • 52