Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

Back button redirect

Is there a way to re-direct if someone hits the back button?  Instead of going back one page I would like to redirect the back button to the homepage.
0
rgranlund
Asked:
rgranlund
  • 2
  • 2
1 Solution
 
Sandar AyeCommented:
Please change the home page link that you want to redirect if someone hits the back button

 jQuery(document).ready(function($) {

        if (window.history && window.history.pushState) {

            window.history.pushState('forward', null, './#forward');

            $(window).on("popstate", function() {
                window.location.href = "http://www.homepage.com";
            });

        }
    });
0
 
omgangCommented:
I just went through an exercise investigating this in ColdFusion.  I was able to accomplish what I wanted by using meta tags in the page headers.  Do a Google search on
meta tag no cache

OM Gang



Example from my CF page
<!--- testing http cache control headers -- OMGang 060216 --->
 <cfheader name="expires" value="#now()#">
 <cfheader name="pragma" value="no-cache">
 <cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
0
 
Dave BaldwinFixer of ProblemsCommented:
If you succeed in doing that, I would avoid going to your web site.  You are trying to take control of my browser in ways that are Not acceptable to me.  I don't know what your actual problem is that you're trying to solve but I don't think that's a good way to do it.
0
 
omgangCommented:
@Dave Baldwin
In my particular circumstance, the goal was to protect user personally identifiable information (PIN) after they had logged out of an application.   The browser back button will reload previously viewed pages that may include PIN and the concern was with users accessing the application from a public browser (kiosk, etc.) and then walking away.  This was a topic of quite some discussion that ultimately concluded with us not implementing the no-cache meta tags but, instead, a displayed message to the user instructing them to close the browser upon logout.  Still, the meta-tag option does provide the functionality the author inquired about.
OM Gang
0
 
Dave BaldwinFixer of ProblemsCommented:
omgang, your problem and solution are not what the original question is about as best I can tell.  There are ways to prevent viewing private info after a logout that do not involve hijacking the Back button.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now