Browser history

Discussion in 'Javascript' started by Linda, Aug 9, 2010.

  1. Linda

    Linda Guest

    <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
    Linda, Aug 9, 2010
    #1
    1. Advertising

  2. Linda

    David Mark Guest

    On Aug 9, 12:51 am, Linda <> wrote:
    > <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.
    David Mark, Aug 9, 2010
    #2
    1. Advertising

  3. On 2010-08-08 09:51 PM, Linda wrote:
    > <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.
    --
    Garrett
    Garrett Smith, Aug 9, 2010
    #3
  4. On 2010-08-08 10:56 PM, Garrett Smith wrote:
    > On 2010-08-08 09:51 PM, Linda wrote:
    >> <input type="button" value="Back" onClick="javascript:
    >> history.go(-1)">
    >>

    > Don't use javascript URIs.
    > <http://jibbering.com/faq/#javascriptURI>
    >


    Sorry, that was not a javascript uri you used; but a meaningless label.
    You don't need that label and if you use a real link (as I suggested in
    my previous message) you're much better off.
    --
    Garrett
    Garrett Smith, Aug 9, 2010
    #4
  5. Linda

    Linda Guest

    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
    Linda, Aug 9, 2010
    #5
  6. Garrett Smith wrote:

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

    >>
    >> Don't use javascript URIs.
    >> <http://jibbering.com/faq/#javascriptURI>

    >
    > 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
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
    Thomas 'PointedEars' Lahn, Aug 9, 2010
    #6
  7. On 09/08/10 16:06, Linda wrote:
    > 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
    Denis McMahon, Aug 9, 2010
    #7
  8. Linda

    Felix Palmen Guest

    * Denis McMahon <>:
    > On 09/08/10 16:06, Linda wrote:
    >> 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 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

    --
    Felix Palmen (Zirias) + [PGP] Felix Palmen <>
    web: http://palmen-it.de/ | http://palmen-it.de/pub.txt
    my open source projects: | Fingerprint: ED9B 62D0 BE39 32F9 2488
    http://palmen-it.de/?pg=pro + 5D0C 8177 9D80 5ECF F683
    Felix Palmen, Aug 9, 2010
    #8
  9. On 2010-08-09 08:06 AM, Linda wrote:
    > 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>
    --
    Garrett
    Garrett Smith, Aug 9, 2010
    #9
  10. Linda

    Linda Guest

    On Aug 9, 5:58 pm, Garrett Smith wrote:

    > 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
    Linda, Aug 10, 2010
    #10
  11. Linda

    Linda Guest

    On Aug 9, 11:34 pm, Garrett Smith wrote:
    > 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
    Linda, Aug 10, 2010
    #11
  12. Linda

    Ry Nohryb Guest

    On Aug 10, 7:59 am, Linda <> wrote:
    > (...)
    > 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.
    --
    Jorge.
    Ry Nohryb, Aug 10, 2010
    #12
  13. On 2010-08-09, Linda wrote:
    ><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>

    --
    Chris F.A. Johnson
    <http://torontowebdesign.cfaj.ca>
    Chris F.A. Johnson, Aug 10, 2010
    #13
  14. On 2010-08-09, Linda wrote:
    ><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>


    --
    Chris F.A. Johnson
    <http://torontowebdesign.cfaj.ca>
    Chris F.A. Johnson, Aug 10, 2010
    #14
  15. Linda

    Linda Guest

    On Aug 10, 5:52 pm, Garrett Smith <> wrote:
    > 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
    Linda, Aug 11, 2010
    #15
  16. Linda

    Linda Guest

    Linda, Aug 11, 2010
    #16
  17. Linda

    Ry Nohryb Guest

    On Aug 11, 4:36 pm, Linda <> wrote:
    > 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); }

    ?
    --
    Jorge.
    Ry Nohryb, Aug 11, 2010
    #17
  18. On Aug 11, 3:36 pm, Linda wrote:
    > 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.
    Richard Cornford, Aug 11, 2010
    #18
  19. On 2010-08-11 07:29 AM, Linda wrote:
    > On Aug 10, 5:52 pm, Garrett Smith<> wrote:
    >> Please don't even try do that.

    >
    > Again, I get it that some here don't think I should do this. It still

    Getting you to a point understanding is proving to be quite difficult.
    --
    Garrett
    Garrett Smith, Aug 12, 2010
    #19
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD

    Re: Browser-History-Back Button

    Steve C. Orr, MCSD, Aug 15, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    2,180
    mathieu cupryk
    Aug 16, 2003
  2. =?Utf-8?B?Um9i?=
    Replies:
    3
    Views:
    14,512
    Steven Cheng[MSFT]
    Jan 21, 2004
  3. Sam Stephenson
    Replies:
    1
    Views:
    215
    Andrew Walrond
    Jun 18, 2005
  4. Replies:
    2
    Views:
    278
    nutso fasst
    Oct 17, 2006
  5. Niall
    Replies:
    3
    Views:
    156
    Niall
    Dec 6, 2006
Loading...

Share This Page