我在登录页面中使用“记住我”选项。 如果用户选中记住我,我将存储用户的信息。 (在本地存储中加密) 一切正常并运行。 但是,如果用户再次打开登录页面,应用程序将在显示登录页面后重定向主页。 我不想再次出现登录页面。 我该如何解决这个问题?
这是我的代码(在登录中使用)
$(document).on("pagebeforechange", function (e, data) {
LoginWithRemember();
});
注意:应用程序使用 JqueryMobile 运行
最佳答案
将此代码放在页面的最顶部:
<html>
<head>
<script type="text/javascript">
if(localStorage.getItem('youRememberMeVariable') &&
localStorage.getItem('yourRememberMeVariable')=='yourRememberMeValue')
window.location='http://yoursite.com/yourMainPage.';
</script>
</head>
....REST of the page ...
</html>
请记住,localStorage
仅在已保存的子域中可用。
关于javascript - 记住我在登录页面加载后运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34832897/