What is the best practice for a "back page" link?

Asked

Viewed 6,417 times

9

Would you like to know what is the best practice for that standard button/link (back) in the applications? Today I use href="javascript:history.back();" however there are some considerations that over time I have come across, are 3 doubts:

  1. INCOMPATIBILITY - I’ve been in situations javascript:history.back(); not being compatible with some specific browsers/versions, and not working, even with client-enabled Javascript. Would there be any other measure to be used for this situation?

  2. OPTIONS - I know that href="javascript:history.back();" returns to the client’s last navigation page, and if needed to return 2 pages with Javascript?

  3. PHP - Knowing that it is a server-side language, even so, there would be something in PHP to do this function, native or not, and not using Javascript?

Note: Regarding doubt 3, I have already used in some systems a kind of page capture per session, where a history was assembled accompanying navigation, this way could direct a link back to any level of browsing history, because sometimes I need to go back one, two, or even 3 pages of this history, I discontinued this function in the new systems because I believed it was too unnecessary processing, and ended up using only javascript:history.back(); and when necessary on specific occasions do a "gambiarra".

1 answer

12


Answer 1:

It has this method, but it’s the same as the one you used, and it doesn’t work on some browsers.

<a href="javascript: history.go(-1)">Voltar</a>

This can solve the incompatibility problem:

<a href="javascript:void(0)" onClick="history.go(-1); return false;">Voltar</a>

Answer 2:

Just use the same command and change the -1 to -2, and so respectively.

<a href="javascript: history.go(-2)">Voltar 2 páginas no histórico</a>

Answer 3:

I prefer to use sessions like you said, because it ensures that there will be no incompatibilities. There is the PHP header() function, but it may not work on protected pages "HTTPS".

header('Location: '.$_SERVER['HTTP_REFERER']);
  • 2

    Thank you very much for your reply, cleared all doubts. Answer 2 worked perfectly, the question of compatibility with time we will know through feedbacks.

  • 2

    Congratulations on the well organized question, it is very well formatted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.