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
Solved

Go to login page if trying to reach old pages

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 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