Sunday, June 29, 2008

Restricting user to visit previous pages after user logs out


ShareThis
Its have been a crital task for me for a variety of web aps for restricting users to visit previous pages after he logs out. I have did a lot of research and got many solutions, from using meta tags, to altering the request's headers etc. but the best way I found is by suing Java script along with these mentioned methods.

Particularly using two or more methods make the solution fool proof..
I will write a detailed article on this sub. soon till intereste dfolks should read this good java script resourse...

http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript

Some more relevant posts resourses over the net:
Pragma: No-cache" Tag May Not Prevent Page from Being Cached

how could I disable the browser's back button using javascript?
------------------->
About the only way you can do this is to open a new window using window.open() (specifying that the browser history should not be copied to the new window) and then close the existing one.
=======================================


It can be done in 4+ browsers but it doesn't really disable the back button, just erases the data behind it to an extant.

replace Method
The replace method replaces the current History entry with the specified URL. After calling the replace method, you cannot navigate back to the previous URL using the browser's Back button.

Syntax: location.replace(URL)

This will replace the history with the current link every time a link is clicked
code/font>

<SCRIPT>
function getTag(el,str) {
while ((el!=null) && (str.indexOf(el.tagName + ":")<0))
el = el.parentElement
return el
}

function navigateTo(sURL,target) {
if ((target == '_self') | | (target=="")) {
window.location.replace(sURL);
return false;
}
if (target == '_top') {
top.window.location.replace(sURL);
return false
}
if (target =='_parent') {
parent.window.location.replace(sURL);
return false;
}
if (target == '_blank' | | parent.frames.length < 1) {
window.open(sURL, target);
return false;
}
else {
if (parent.frames[target])
parent.frames[target].location.replace(sURL);
else
window.open(sURL, target);
return false;
}
}

function checkIEClick() {
var el = getTag(event.srcElement,"A:AREA:")
if ((el!=null) && ((el.tagName=="A") | | (el.tagName=="AREA"))) {
event.returnValue = false
navigateTo(el.href,String(el.target).toLowerCase())
}
}

function checkNSClick(ev) {
if (ev.target.href) {
navigateTo(ev.target.href,String(ev.target).toLowerCase())
return false
}

}

if ((document.all) | | (document.layers))
if (document.layers) {
document.captureEvents(Event.CLICK)
document.onclick = checkNSClick
}
else
document.onclick = checkIEClick
</SCRIPT>
[/code]

A little slick redirection:
code/font>

<META HTTP-EQUIV="Refresh" CONTENT="1; http://www.insideDHTML.com/home.asp">
<SCRIPT>
<!--
var version = parseInt(navigator.appVersion)
// replace is supported
if (version>=4 | | window.location.replace)
window.location.replace("newPage.htm")
else
window.location.href = "newPage.htm"
// -->
</SCRIPT>
The document, <A HREF="newPage.htm">Scott's Home</A> has moved.
[/code]

The above code was found at Site Experts. I hope it is useful.
==========
Wayne Luke - Sitepoint Forums Administrator
(http://www.sitepoint.com/forums/showthread.php?t=8315)
===================================================================

Here are some work arounds but not fool froof as the auther him self says:

http://www.htmlgoodies.com/tutorials/buttons/article.php/3478911
http://www.irt.org/script/311.htm

===================================================================