用Java脚本注销 [英] Log Out In Java Script
问题描述
我是一个使用Java作为脚本编写语言的网站.我创建了一个注销按钮,然后单击该按钮的onclick我跳到主页.但是问题是当我单击后退按钮时,它再次进入内部而不要求登录.我该如何避免这种情况.我可以清除Web浏览器的历史记录还是必须用另一种方式来做?PLZ帮助我.
I a creating a website using java as scripting lang.I have created a logout button and onclick of that button i jump to home page.But problem is that when i click back button it again go to inside without ask to login.how can i avoid this.can i clear history of web browser or i have to do it another way?plz help me.
推荐答案
好,您需要清除会话Cookie,您应该在服务器端执行此操作,而不是从javascript执行.用户如何登录?
Well you need to clear the session cookie which you should do serverside and not from javascript. How does the user log in?
由于高速缓存而发生这种情况.
1.清除会话
2.清除缓存,使浏览器没有历史记录(这将使浏览器中的后退/前进"按钮变为灰色).
清除缓存的代码可以放在下面的代码中:
This happens because of cache.
1. clear the sessions
2. clear the cache such that browser has no history (this will make back/forward button in browser grayed out disabled.)
code for clearing cache can be put up in code behind as follows:
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
或
您可以将类似的东西添加为aspx格式:
OR
You can add somethin similar in form aspx if you want to place it there:
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0"></meta></meta></meta>
或
您可以通过JavaScript清除浏览器历史记录....
OR
You can clear browser history through JavaScript....
//clears browser history and redirects url
<SCRIPT LANGUAGE=javascript> { var Backlen=history.length; history.go(-Backlen); window.location.href=page url }</SCRIPT>
或
OR
Page.ClientScript.RegisterStartupScript(this.GetType(),"cle","windows.history.clear",true);
或
如您在登出事件中所说:
OR
as you say in you logout event:
protected void LogOut()
{
Session.Abandon();
string nextpage = "Logoutt.aspx";
Response.Write("<script language=javascript>");
Response.Write("{");
Response.Write(" var Backlen=history.length;");
Response.Write(" history.go(-Backlen);");
Response.Write(" window.location.href='" + nextpage + "'; ");
Response.Write("}");
Response.Write("</script>");
}
这篇关于用Java脚本注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!