Browser history

L

Linda

<input type="button" value="Back" onClick="javascript:
history.go(-1)">

In the previous page, the link to the current page is at the bottom of
the page. When I hit the back button on the current page, when the
previous page loads, it opens near the bottom of the page (where the
link is located). Is there a way to make the previous page open at
the top of the page using the onclick of this button?

Linda
 
D

David Mark

<input type="button" value="Back" onClick="javascript:
history.go(-1)">

That should be avoided, meaning both the "javascript:" label (which
does nothing here) and the use of the history.go method.
In the previous page, the link to the current page is at the bottom of
the page.  When I hit the back button on the current page, when the
previous page loads, it opens near the bottom of the page (where the
link is located).  Is there a way to make the previous page open at
the top of the page using the onclick of this button?

Yes, if you know the address of the previous page you could set
window.location.href. Of course, then you could use a static link
instead of a scripted button.
 
G

Garrett Smith

<input type="button" value="Back" onClick="javascript:
history.go(-1)">
Don't use javascript URIs.
<http://jibbering.com/faq/#javascriptURI>

What if it is an off-site link, or if there is no referring link?

A link is the way to go; you'll need some sort of server side logic to
get that URI.
In the previous page, the link to the current page is at the bottom of
the page. When I hit the back button on the current page, when the
previous page loads, it opens near the bottom of the page (where the
link is located). Is there a way to make the previous page open at
the top of the page using the onclick of this button?
What for? That sounds like a broken experience.
 
L

Linda

OK. I get it that no one here thinks that this is a good idea. But,
without going into a long description of the "why" I want to do this,
is there a way to return to the top of an unknown page with a link or
with a button rather than to the point of the link on the referring
page?

Linda
 
T

Thomas 'PointedEars' Lahn

Garrett said:
Sorry, that was not a javascript uri you used; but a meaningless label.

It is not always considered a meaningless label (and might even be
considered a syntax error), but given JScript being the default in MSHTML,
and its VBScript not being universally supported client-side, the label
should not be necessary to use.
You don't need that label

There is not enough information in the posting to support that assumption.
and if you use a real link (as I suggested in my previous message) you're
much better off.

ACK


PointedEars
 
D

Denis McMahon

OK. I get it that no one here thinks that this is a good idea. But,
without going into a long description of the "why" I want to do this,
is there a way to return to the top of an unknown page with a link or
with a button rather than to the point of the link on the referring
page?

I think it's a feature of the way some browsers handle cached pages.

I suspect that some browsers remember where on the page the user was
looking when they navigated away from the page, and if they return to
the page eg using the back button, it takes them back to where they were.

Whether it can be over-ridden or not by anything you do server-side or
in the html I have no idea, although expiring the page might help.

Rgds

Denis McMahon
 
F

Felix Palmen

* Denis McMahon said:
I suspect that some browsers remember where on the page the user was
looking when they navigated away from the page, and if they return to
the page eg using the back button, it takes them back to where they were.

Right, and in my experience, this feature is canceled by any manual
scrolling action of the user, so /maybe/ a window.scrollTo(0,0) would
cancel it, too. Still that means disabling a useful feature...

Regards, Felix
 
G

Garrett Smith

OK. I get it that no one here thinks that this is a good idea. But,
without going into a long description of the "why" I want to do this,
is there a way to return to the top of an unknown page with a link or
with a button rather than to the point of the link on the referring
page?

A fragment identifier is the way to do that:
<a href="/#top">Go Back</a>

For help on posting and replying, I suggest you read:
<http://jibbering.com/faq/#posting>
 
L

Linda

A fragment identifier is the way to do that:
<a href="/#top">Go Back</a>

This looked interesting. I tried using it as written but it did not
work as I expected. I am using Safari 5.0.1 on Mac OS X. When I
click on the Go Back link, it opens Finder to the root directory on
the Mac.

Linda
 
L

Linda

So you are using a local file protocol, huh?
Yes.
First change the path in that link to go to the page you want to link
to. Next, set the fragment identifier to point to the id of an element
(or a named anchor) in the target page.

The previous page is not always the same page. I think that I
understand that what you are writing is that I should use:

<a href="somepage.html#top">

However, I need to use the browser's history instead since I will not
always know which was the previous page. i.e. "somepage.html" may not
always be the referrer.

When the Back button is clicked on the second page, I want to go to
the top of the referrer and not to the position in the page where
there was a link to the second page.

This should be a javascript question rather than an HTML question.

Linda
 
R

Ry Nohryb

(...)
When the Back button is clicked on the second page, I want to go to
the top of the referrer and not to the position in the page where
there was a link to the second page. (...)

If by "back button" you mean the browser's back button, then I think
the answer is no, you can't. IIRC it's not possible to read the
history object's entries. IIRC you can only do history.back() and
history.forward() and history.go(), but when you do so you've got no
chance to clean the "#" from the destination url before navigating to
it, which is what you seem to need.

But if you've put your own back button in the page, you could attempt
to go back by doing something like location.href=
cleanUp(document.referrer), where cleanUp takes care of removing any #
part of the referer url, methinks.
 
C

Chris F.A. Johnson

<input type="button" value="Back" onClick="javascript:
history.go(-1)">

In the previous page, the link to the current page is at the bottom of
the page. When I hit the back button on the current page, when the
previous page loads, it opens near the bottom of the page (where the
link is located). Is there a way to make the previous page open at
the top of the page using the onclick of this button?

<http://cfajohnson.com/testing/a001.html>

Files go from a001 to z999.

The script that does the work is
<http://cfajohnson.com/testing/back.cgi>, which you can see here:
<http://cfajohnson.com/testing/back.txt>
 
C

Chris F.A. Johnson

<input type="button" value="Back" onClick="javascript:
history.go(-1)">

In the previous page, the link to the current page is at the bottom of
the page. When I hit the back button on the current page, when the
previous page loads, it opens near the bottom of the page (where the
link is located). Is there a way to make the previous page open at
the top of the page using the onclick of this button?

<http://cfajohnson.com/testing/a001.html>

Files go from a001 to z999.

The script that does the work is
<http://cfajohnson.com/testing/back.cgi>, which you can see here:
<http://cfajohnson.com/testing/back.txt>
 
L

Linda

Please don't even try do that.

Again, I get it that some here don't think I should do this. It still
does not answer the question of how to do it. Nevertheless, I now
have it working on local files using javascript, which was the goal. I
apologize for not stating that in my first post.

Linda
 
R

Ry Nohryb

Here is the result. It works on local files too.

http://www.anmldr.com/t/

Sort of... as you're saving only one -the last- page in the cookie,
you can never go back more than 1 page, for example, clicking "back"
won't take you back from page 3 to page 1...

If all that you're after is to scroll the page to the top onload, why
don't you just scrollTo onload ?

window.onload= function () { window.scrollTo(0,0); }

?
 
R

Richard Cornford

Here is the result. It works on local files too.

http://www.anmldr.com/t/

Only for some value of 'works' where if you go forward to page 3 and
then use the BACK link to go back to page 2 the BACK link on page 2
links to page 2 so it will not go back to page 1 or return to page 3,
which is what the browser's back button would do at that point.

Richard.
 

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top