Solved

Go to login page if trying to reach old pages

Posted on 2013-11-07
5
167 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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)

707 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

15 Experts available now in Live!

Get 1:1 Help Now