?
Solved

Back button redirect

Posted on 2016-08-25
5
Medium Priority
?
124 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Sandar Aye earned 2000 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 84

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 84

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

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

719 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