![](/img/trans.png)
[英]jQuery fallback when localStorage/sessionStorage is disabled
[英]rails 3 devise : destroy localStorage and sessionStorage when logout?
我正在使用Rails 3 devise,并且已经创建了一些HTML 5 Web存储。 现在,如果用户单击注销链接,我想显示一条确认消息。 如果用户单击确定按钮,我想将sessionStorage值设置为null,现在用户将从应用程序注销。
我正在继承设计会话控制器,如:
class SessionController < Devise::SessionController
def destroy
# code ?
end
end
实际上,我可以使用javascript代码将sessionStorage值设置为null:
<script>
$(document).ready(function(){
if(confirm("Are you sure want to logout?")){
sessionStorage.value = null;
}
return false;
})
</script>
但是,当用户单击注销链接时,如何实现此代码? 如何解决这个问题?
您可以通过使注销方法重定向来执行Javascript操作。 例如:
def destroy
// ... other actions...
redirect_to destroy_localstore_path
end
def destroy_localstore
end
在您的destroy_localstore.js.erb中...
sessionStorage.value = null;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.