javascript - 记住我在登录页面加载后运行

标签 javascript html jquery-mobile remember-me autologin

我在登录页面中使用“记住我”选项。 如果用户选中记住我,我将存储用户的信息。 (在本地存储中加密) 一切正常并运行。 但是,如果用户再次打开登录页面,应用程序将在显示登录页面后重定向主页。 我不想再次出现登录页面。 我该如何解决这个问题?

这是我的代码(在登录中使用)

        $(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/

相关文章:

javascript - 元素的同位素高度设置不正确

javascript - 如何添加文本字段的值

jquery - 简单的 jQuery 动画

jQuery mobile 和 js 的双重执行

javascript - 区分 webRequest.onBeforeRequest 原始页面与注入(inject)页面

javascript - 如何使用 jQuery(或 vanilla JS)在选项卡上创建新输入

javascript - 这里我想在ajax中加载数据 hide show div

javascript - 从url获取字符串值

javascript - 根据url参数设置下拉值

jQuery Mobile CSS 滚动和点击