beginner: href link like "back" button

M

Ma³y Piotruœ

Hello,
(Sorry for my english.)
I am new to HTML/JavaScript/CSS. I would like to ask for help with
such a problem:
I need to create a href link working like "back" button (I know this
is not recommended by it's not my idea, and I must respect this
requirement.) I did it this way:

<a href="javascript:history.back()">Back</a>

Unfortunatelly it does not work (nothing happends when clicked.)
Could you tell me please how to write it correctly?
Thank you very much.
 
M

McKirahan

Ma³y Piotruo said:
Hello,
(Sorry for my english.)
I am new to HTML/JavaScript/CSS. I would like to ask for help with
such a problem:
I need to create a href link working like "back" button (I know this
is not recommended by it's not my idea, and I must respect this
requirement.) I did it this way:

<a href="javascript:history.back()">Back</a>

Unfortunatelly it does not work (nothing happends when clicked.)
Could you tell me please how to write it correctly?
Thank you very much.

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

Thomas 'PointedEars' Lahn

McKirahan said:
Ma³y Piotruo said:
[...]
<a href="javascript:history.back()">Back</a>

Unfortunatelly it does not work (nothing happends when clicked.)
Could you tell me please how to write it correctly?
Thank you very much.

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

That is equivalent to the above and just as bad.


PointedEars
 
R

RobG

Ed said:
McKirahan wrote:

[...]
<a href="javascript:history.back()">Back</a>

Unfortunatelly it does not work (nothing happends when clicked.)
Could you tell me please how to write it correctly?
Thank you very much.

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

That is equivalent to the above and just as bad.

What is so bad about using it?

It is unreliable - the page has no idea whether history.go() will work,
where it will go or even if there is anything to go to, either forward
or backward.

Browsers already have forward/backward buttons that provide much more
functionality (e.g. lists of pages to go back/forward to) and are
reliable (e.g. greyed-out if there is nothing to go back/forward to).

Putting script in the HREF attribute of an A element means users without
JavaScript have a link that does absolutely nothing.

If the intention is to supply navigation to previous/next pages in a
site, they should be coded as links (i.e. A elements with non-script
dependent HREF attributes).

If the OP's client/employer wishes to implement such functionality, the
issues should be clearly spelled out.
 
T

Thomas 'PointedEars' Lahn

RobG said:
Ed said:
Thomas 'PointedEars' Lahn said:
McKirahan wrote:
[...]
<a href="javascript:history.back()">Back</a>

Unfortunatelly it does not work (nothing happends when clicked.)
[...]
<a href="javascript:history.go(-1)">
That is equivalent to the above and just as bad.
What is so bad about using it?

It is unreliable - the page has no idea whether history.go() will work,
where it will go or even if there is anything to go to, either forward
or backward.

Browsers already have forward/backward buttons that provide much more
functionality (e.g. lists of pages to go back/forward to) and are
reliable (e.g. greyed-out if there is nothing to go back/forward to).

ACK. The functionality of this UA feature can be re-implemented through
scripting under certain circumstances, though it is not to be recommended
in the general case, as here.
Putting script in the HREF attribute of an A element means users without
JavaScript have a link that does absolutely nothing.

Which is, however, something that can be worked around if the
`a' element would be created using client-side scripting.
If the intention is to supply navigation to previous/next pages in a
site, they should be coded as links (i.e. A elements with non-script
dependent HREF attributes).

If the OP's client/employer wishes to implement such functionality,
the issues should be clearly spelled out.

Full ACK.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top