Back to previous page/section

L

Linda

I have a long list of links (index of a book), I know that I can use
<a href="javascript: history.go(-1)">Back</a> to go back to the
previous page. However, I would also prefer to go back to the portion
of the page that contained the link that I clicked. What would be the
syntax for this?

Thank you,
Linda
 
T

Trevor Lawrence

Linda said:
I have a long list of links (index of a book), I know that I can use
<a href="javascript: history.go(-1)">Back</a> to go back to the
previous page. However, I would also prefer to go back to the portion
of the page that contained the link that I clicked. What would be the
syntax for this?

<a href="callingpage.html#callmark">Back to Index</a>
where callingpage.html is the calling page and #callmark is the name of an
anchor on that calling page
e.g.
<a name="callmark">
This is where you put the links
</a>

Of course, I just used he name "callmark" as an example - it can be anything
 
R

rf

Linda said:
I have a long list of links (index of a book), I know that I can use
<a href="javascript: history.go(-1)">Back</a> to go back to the
previous page. However, I would also prefer to go back to the portion
of the page that contained the link that I clicked. What would be the
syntax for this?

<p>Please use your browsers Back function to return to the index.</p>
 
L

Linda

<p>Please use your browsers Back function to return to the index.</p>

Sorry but this is not what I was looking for.
 
D

David Mark

 <p>Please use your browsers Back function to return to the index.</p>

Sorry but this is not what I was looking for.

Why are you trying to re-invent the back button?
 
T

Thomas 'PointedEars' Lahn

Linda said:
I have a long list of links (index of a book), I know that I can use
<a href="javascript: history.go(-1)">Back</a> to go back to the
previous page. However, I would also prefer to go back to the portion
of the page that contained the link that I clicked. What would be the
syntax for this?

window.history.go(-1) or window.history.back() would do that, in a good
browser (such as Firefox) that also has script support enabled, as (AFAIK)
they do nothing else than the Back feature/button does.

However, you rarely would want to use the former, and you certainly would
want to feature-test it before you used it if you used it. Unfortunately,
there is no feature test as to whether calling it had an effect (you can't
retrieve the length of the history), so this feature cannot degrade
gracefully completely. So you better don't use it.

As for your "link", please see <http://jibbering.com/faq/#javascriptURI>.

Did I already mention that you SHOULD NOT do that here?


PointedEars
 
D

David Mark

window.history.go(-1) or window.history.back() would do that, in a good
browser (such as Firefox) that also has script support enabled, as (AFAIK)
they do nothing else than the Back feature/button does.

Which, of course, means the behavior is not predictable by the script
(the link could lead anywhere or nowhere.)
However, you rarely would want to use the former, and you certainly would

Why is the latter any better?
want to feature-test it before you used it if you used it.  Unfortunately,
there is no feature test as to whether calling it had an effect

Yes, this is true of a lot of host methods. Do you know of an
environment where the history object has ineffectual methods? ISTM
that if the methods are there then there is very good chance they will
do what is expected (which includes the possibility of nothing.)

Of course, I agree that there is no guarantee; but if all such methods
are dismissed out of hand, ISTM that little would be left to call. I
also agree that these methods are best left alone, but for other
reasons.

[snip]
 
T

Tim Greer

Linda said:
I have a long list of links (index of a book), I know that I can use
<a href="javascript: history.go(-1)">Back</a> to go back to the
previous page. However, I would also prefer to go back to the portion
of the page that contained the link that I clicked. What would be the
syntax for this?

Thank you,
Linda

You could try adding an anchor tag. However, also, always have
something to fall back on in case someone has JS disabled. One idea is
to create a (hot)link dynamically, if you can (such as using something
server-side)... again, to fall back on, just in case.
 
T

Thomas 'PointedEars' Lahn

David said:
Which, of course, means the behavior is not predictable by the script
(the link could lead anywhere or nowhere.)

"Anywhere" would be well defined: the previous item in the window's history.
"Nowhere" (maybe augmented with an error message that the user can hardly
understand) is a distinct possibility, indeed.
Why is the latter any better?

The Back feature/button is meant with "the latter" here. AFAIK, in contrast
to the pseudo-link, it is automatically disabled (and colored so) if it
would not work.
Yes, this is true of a lot of host methods. Do you know of an
environment where the history object has ineffectual methods?

All environments where the window's history is empty, which is what I was
referring to. However, you are of course correct that cases where it does
not work despite a non-empty history have to be considered. I know of no
such case, though, mostly because I have not tested this feature more
thoroughly yet. But the Matrix has you, thanks for that.


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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top