Solved

Go to login page if trying to reach old pages

Posted on 2013-11-07
5
172 Views
Last Modified: 2013-11-25
What do I need to do if I want the browser to go to the login page if I for instance try to reach  old url:s from the history?

I use html and javascript on jboss.
0
Comment
Question by:mdoland
5 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 39630158
from Web Browsing History ???
I am not sure if that can be done

if it was a cookie from within your page you could do a simple javascript if statement  to redirect to the url.. from a logical standpoint I cannot think of a way to do it form your browser history.
 
OR are you talking about hitting the back button in the broswer and going back to previous page ?
0
 

Author Comment

by:mdoland
ID: 39630164
Yes, hitting the back button is a good example.
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39630222
unfortunately you cannot detect if a user hits the back button :(

only think i can really think of to try is a  javascript function in the body of your HTML


function redirect(){
  window.location = "www.google.com";
}

<!--before your </body> tag -->
<body onload="redirect()">
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39630503
You cannot prevent the user from accessing the historical pages; nor should you attempt such a hack.  All you will do is make the page less acccessible and any user with an ounce of sense will avoid the page in the future as it should be regarded as a potentially dangerous page.

You are trying to override user controls and fortunately modern browsers are not going to let you do it.

In some browsers you can put up a message using a beforeunload event, but you cannot force the user to go to a home page or anywhere else.

Cd&
0
 
LVL 10

Accepted Solution

by:
GeoffSutton earned 500 total points
ID: 39632581
//set the cookie with date or other session variable when page loads

document.cookie.last_used=new Date()
....

//check the cookie to see if the session is expired, and if so redirect to login page
if((new Date(document.cookie.last_used).day!=(new Date()).day){
  location.href="login.html"
}

I would not recommend using this in this fashion.  Rather, I would update the cookie on every page load and set the timeout to 5 minutes.  That way, if the user leaves the page for longer than 5 minutes they will be redirected to the home page.  You may need to play with the times, and also you may want to update the cookie on mousemove rather than page load, otherwise you will be redirected if the user browses the page for more than 5 minutes.

Info on setting cookies here:
http://www.w3schools.com/js/js_cookies.asp
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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)

816 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

13 Experts available now in Live!

Get 1:1 Help Now