Solved

Back button redirect

Posted on 2016-08-25
5
47 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
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
@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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

5 Experts available now in Live!

Get 1:1 Help Now