Solved

Back button redirect

Posted on 2016-08-25
5
70 Views
Last Modified: 2016-09-09
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
Comment
Question by:rgranlund
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Sandar Aye earned 500 total points
ID: 41770627
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
 
LVL 28

Expert Comment

by:omgang
ID: 41770630
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41770692
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
 
LVL 28

Expert Comment

by:omgang
ID: 41770732
@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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 41770852
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Two wordpress questions 3 47
"Pause" execution of javascript function for x miliseconds 2 32
replace link with jQuery 4 15
Un-Indent Setting Notepad++ 3 10
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

825 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