Using javascript:history.go(-1) more effectively

Posted on 2007-07-25
Last Modified: 2008-01-09
After adding a record we use <a href="javascript:history.go(-1)">Return to whatever</a> to give the user a way to get back to the page they were viewing before adding a record.  An example of this would be adding an item to an existing order - they need to get back to the original order they added an item to.

the problem with history.go is that it doesn't actually set the hyperlink, it simply returns them to a cached page in their browser's history.  How can I make this so that it replaces the link with an actual URL?  I want the page to actually refresh when they go to it so the new record shows up...I don't want to do any javascript refreshes on the parent page or any sorry fixes like that..

Thanks alot,

Question by:stankstank
    LVL 9

    Expert Comment

    For this you need to set the href value to the url / page which you need to redirect to

    Try the following code

    <a href="Default2.aspx">Test</a>


    Chirag Patel
    LVL 11

    Accepted Solution

    My suggestion would be to keep the link as it is and instead prevent the browser to cache the page in question. If this page is an order page it is probably not a bad idea anyway.  Best practise is to do this server-side if possible. There are multiple ways of doing this, depending on what programming language your page is written in:

    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="pragma" content="no-cache">

    Also, for IE you may want to use another set of head
     tags in the end of your page to prevent the buffer fill:

    ASP or ASP.NET
    <% Response.CacheControl = "no-cache" %>
    <% Response.AddHeader "Pragma", "no-cache" %>
    <% Response.Expires = -1 %>

      Header('Cache-Control: no-cache');
      Header('Pragma: no-cache');

    <cfheader name="Expires" value="#Now()#">
    <cfheader name="Pragma" value="no-cache">

      response.setDateHeader ("Expires", 0);


    LVL 12

    Expert Comment

    if you dont want to cache you can specify

    Response.Cache.SetCacheability (HttpCacheability.NoCache);


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now