Solved

Go to login page if trying to reach old pages

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

690 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